Category: Programming

Schedule Database Backup in SQL Server

1. In Microsoft SQL Server Management Studio, right-click SQL Server Agent, then click New, then click Job

2. Input Name, “JOB_BACKUP_DATABASE”

3. Click Steps, then click New

4. Input Step Name, “BACKUP DATABASE TO DISK”

5. Paste the following Command

DECLARE @todayText char(8)
SET @todayText = CONVERT(char(8), GETDATE(), 112)

DECLARE @path nvarchar(256)
SET @path = N'D:\DatabaseBackup\DB_NAME.{DATESTAMP}.bak'
SET @path = REPLACE(@path, '{DATESTAMP}', @todayText);

BACKUP DATABASE [DB_NAME]
    TO  DISK = @path
    WITH NOFORMAT, NOINIT,  NAME = N'DB_NAME - Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

6. Click OK

7. Click Schedules, then click New

8. Input Name, “Daily 18:00″

9. Setup the appropriate schedule

10. Click OK

11. Click OK again

Advertisements

Windows Search SDK

Setup Environment
1. Install Microsoft Windows SDK

2. Install Microsoft Windows Search SDK

How to Add Indexing Location

CSearchManager searchManager = new CSearchManager();
CSearchCatalogManager catalogManager = searchManager.GetCatalog("SystemIndex");
CSearchCrawlScopeManager crawlScopeManager = catalogManager.GetCrawlScopeManager();

crawlScopeManager.AddUserScopeRule(@"file:///D:\My Documents\", 1, 1, 1);
crawlScopeManager.SaveAll();

catalogManager.Reindex();

How to Search Indexed Location

CSearchManager searchManager = new CSearchManager();
CSearchCatalogManager catalogManager = searchManager.GetCatalog("SystemIndex");

CSearchQueryHelper queryHelper = catalogManager.GetQueryHelper();
queryHelper.QueryWhereRestrictions = @"AND scope='file:D:\My Documents\'";

string sql = queryHelper.GenerateSQLFromUserQuery("Hello World");

using (OleDbConnection conneciton = new OleDbConnection(queryHelper.ConnectionString))
{
	using (OleDbCommand command = new OleDbCommand(sql, conneciton))
	{
		conneciton.Open();
		using (OleDbDataReader dataReader = command.ExecuteReader())
		{
			while (dataReader.Read())
			{
				Console.WriteLine(dataReader[0]);
			}
		}
	}
}

References

Password Policy Check in ASP.NET Membership

There are 3 attributes in ASP.NET Membership Providers for configuring the password policy check.

1. minRequiredPasswordLength
Specifies the minimum number of characters that are required in a password. The default is 7.

2. minRequiredNonalphanumericCharacters
Specifies the minimum number of special characters that must be present in a valid password. The default is 1.

3. passwordStrengthRegularExpression
Specifies the regular expression that is used to evaluate a password. The default is an empty string (“”).

The following is a sample of ASP.NET Membership Provider Configuration.

<membership defaultProvider="SqlMembershipProvider" userIsOnlineTimeWindow="30">
  <providers>
    <clear />
    <add name="SqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" applicationName="MyApplication" 
      minRequiredPasswordLength="8" 
      minRequiredNonalphanumericCharacters="1" 
      passwordStrengthRegularExpression="^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=(.*\W)).{8,128}$" />
  </providers>
</membership>

The above configuration validates the password to meet the following criteria:
+ It is at least 8 characters and not exceed 128 characters
+ It contains at least 1 lower-case character
+ It contains at least 1 upper-case character
+ It contains at least 1 numeric character
+ It contains at least 1 special (non-alphanumeric) character

References

Set CacheControlMaxAge to High Number

It’s a good practice to set the CacheControlMaxAge attribute in web.config to a high number.

<system.webServer>
	<staticContent>
		<!-- Set expire headers to 30 days for static content-->
		<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="30.00:00:00" />
	</staticContent>
</system.webServer>

Turn On HTTP Compression

It’s a good practice to enable HTTP compression for any uncompressed content. Add the following code snippet in web.config.

<system.webServer>
	<!-- GZip static file content. Overrides the server default which only compresses static files over 2700 bytes -->
	<httpCompression directory="%SystemDrive%\websites\_compressed" minFileSizeForComp="1024">
		<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
		<staticTypes>
			<add mimeType="text/*" enabled="true" />
			<add mimeType="message/*" enabled="true" />
			<add mimeType="application/javascript" enabled="true" />
			<add mimeType="application/json" enabled="true" />
			<add mimeType="*/*" enabled="false" />
		</staticTypes>
	</httpCompression>
</system.webServer>