Thursday, July 28, 2011

Computed column expressions in SQL

SQL table column can be defined as a computed column expression, which is not a physical column in that table, unless specifically given as PERSISTED. The value is derived from some other columns in the same table.

Why it should be persisted?

If you have to calculate the value in each time a user request for it, then it will consume more processor time. So, making it "persistent" will save data in the disk which will reduce CPU contention.

However, if there is a concern on the disk space limitations, leaving it non-persistent would be ideal.

Monday, July 25, 2011

Which C# collection you should use to meet your requirement?

If you want sequential access to your collection, use stack (LIFO) or queue (FIFO). If you need to access each element by index you can use an ArrayList or List.

Using HashTable and Dictionary classes you can access an item in the collection by key.

If you want to sort the list. you can use SortedList or SortedDictionary and customize the way items are sorted using the IComparer interface.

Thursday, July 21, 2011

Difference between UNIQUE constraint and PRIMARY KEY constraint

You can use a UNIQUE constraint if you want to give uniqueness to a column which is not primary key.

You can have more than one UNIQUE constraints in a table, where as there can be only one PRIMARY KEY in a table.

To modify a PRIMARY KEY constraint, you need to drop it and re-create.

Also, PRIMARY KEY column should be NOT NULL and UNIQUE constraints can be null.

If CLUSTERED or NONCLUSTERED is not specified for a PRIMARY constraint, the default value will be CLUSTERED.

If no clustered indexes are specified for UNIQUE constraint, NONCLUSTERED is set as default value.

Since a table can have only one clustered key, if you define a PRIMARY constraint and if it is not NONCLUSTERED, you can't specify a UNIQUE constraint as CLUSTERED.

Sunday, July 17, 2011

What's new in ASP.NET 4.0: Simplified default web config

With the invention of new CLR, ASP.NET 4.0 has simplified the application level web.config file by moving most of the configurations to machine.config.

Some of the eliminated items are:
httphandlers, http modules, assembly binding

How to add custom browser definition files?

ASP.NET uses browser definition files to determine the capabilities of the browser (Ex: JavaScript, cookies, ActiveXControls etc.) which request comes from. Accordingly it will create the mark up as the response to client.

Browser definition files are located in, C:\WINDOWS\Microsoft.NET\Framework\\CONFIG\Browsers\

To add a custom browser definition file, copy the *.browser file to the above location and run Aspnet_regbrowsers.exe tool.

You can add custom browser files in App_Browsers folder in ASP.NET web site as well.

MIME types in HTTP content

HTTP response contains a content type (Ex: text/html) which describes the type of resource which is sent back to the browser. This is a MIME (Multipurpose Internet Mail Extensions) type.

MIME type contains two parts which the first part represents the resource type and the next part represents the resource sub type.

The common MIME types contains the following:

  • Text - HTML, Plain text, XML

  • Image - jpeg, png

  • Audio

  • Video

  • Application

The browser will process the content based on it's MIME type.

To be continued...

Web communication @ a glance!

Thursday, July 14, 2011

Add an executable to Windows right click menu for a file type

To give a customized menu as given above:

  1. Go to My Computer

  2. In Tools > Folder Options, Go to File Types

  3. Select the file type you want to add the menu item to (Ex: for *.sql - Microsoft SQL Server Query File)

  4. Click "Advanced"

  5. Click "New"

  6. In New Action, give the name you want to appear in right click menu in Action field

  7. Give the absolute path to the executable in "Application used to perform action" field

  8. Click OK.

Monday, July 11, 2011

Get the performance of an application running in Windows

  1. Open Perfomance monitor (Run > Perfmon)

  2. Add new counter (Right click > Add Counters)

  3. Select "Process" as Performance object.

  4. Select the required counters from the list. (Click "Explain" to get the definition for each counter)

  5. Available - executing process instances will be displayed in "Select instances from list"

  6. Select the process related to your application.

  7. Click Add.

All in one 2!

All in one!