Tuesday, December 15, 2009

Static Class

Static classes are used when a class provides functionality that is not specific to any unique instance. Here are the features of static classes in C# 2.0.

•Static classes can not be instantiated.
•Static classes are sealed so they can not be inherited.
•Only static members are allowed.
•Static classes can only have static constructor to initialize static members.

Advantages :
Compiler makes sure that no instance of static class is created. In previous version of C#, the constructor has to be marked private to avoid this from happening.

Also compiler makes sure that no instance members are declared within a static class.

One of the biggest problems we VB developers migrating to C# face is understanding STATIC. Static constructors, static data, static member functions, static properties.

To a VB developer, “static” means a variable inside a function (method) whose value remains “live” between function calls, but which is invisible outside the function. In C#, there is no such concept, because it’s not necessary when you can define member fields instead.

What is the purpose of connection pooling in ado.net

Connection pooling enables an application to use a connection from a pool of connections that do not need to be re-established for each use. Once a connection has been created and placed in a connection pool, an application can reuse that connection without performing the complete connection creation process.

By default, the connection pool is created when the first connection with a unique connection string connects to the database. The pool is populated with connections up to the minimum pool size. Additional connections can be added until the pool reaches the maximum pool size.

When a user request a connection, it is returned from the pool rather than establishing new connection and, when a user releases a connection, it is returned to the pool rather than being released. But be sure than your connections use the same connection string each time. Here is the Syntax

conn.ConnectionString = “integrated Security=SSPI; SERVER=192.168.0.123; DATABASE=MY_DB; Min Pool Size=4;Max Pool Size=40;Connect Timeout=14;”;

What is Strong Name/Key

In Microsoft.Net a strong name consists of the assembly’s identity. The strong name guarantees the integrity of the assembly. Strong Name includes the name of the .net assembly, version number, culture identity, and a public key token. It is generated from an assembly file using the corresponding private key. Steps to create strong named assembly: To create a strong named assembly you need to have a key pair (public key and a private key) file.

Use sn -k KeyFile.snk Open the dot net project to be complied as a strong named assembly. Open AssembyInfo.cs/ AssembyInfo.vb file. Add the following lines to AssemblyInfo file. [Assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyDelaySign(false)] [assembly: AssemblyKeyFile("..\\..\\KeyFile.snk")] Compile the application, we have created a strong named assembly.

Asp.net Reserved/ App folder

This article is about the special "reserved" folders that are used in an ASP.NET project, such as App_Code or App_Data. Each one is discussed in details, with suggested uses for it.

Note that your ASP.NET project may or may not contain these directories. They are optional, and the uses given by Microsoft are only suggested uses. You are free to use them or not use them, for any purpose you like.

If you want to add one of these folders, go to Solution Explorer and right-click on your project's name at the top of the list. Select "Add ASP.NET folder" and pick the one(s) you want to add.

App_Data can be used to store datafiles such as databases that are used by this application. One common use is as a location to store the ASPNETDB.MDF file that is used to store usernames and passwords for authenticated website access.

App_Code is typically used to store .cs or .vb files that contain classes that are needed by your main code. Any file you put in here is automatically referenced in your main application, which is very handy. I put libraries of useful functions wrapped up in a static class here, and the compiler automatically picks them up and uses them.

App_Browsers stores special config files for individual browsers' settings. I've never needed to use this, but if you are writing code to target many unusual browsers, perhaps you could find a use for it.

App_GlobalResources is used to store .resx and .resources files, such as files for translation of your website into different languages. These files apply to the entire project.

App_LocalResources is a reserved folder name that is like App_GlobalResources, except that you can have more than one of them, in any folder in your application. It acts like a local version of App_GlobalResources that only applies to that particular folder.

App_Themes is a folder used to store any files that change the appearance of the website, such as .css files, .skin files, or images that are used in a certain theme.

Bin is the folder to put .dll files in if you want your whole application to have access to the dll file. Anything you put here, such as a third-part control, is available to your whole application.

App_WebReferences is a mystery folder that I don't understand yet!

Tuesday, December 1, 2009

Difference Between binary_checksum and checksum

binary_checksum is used to compare password only but checksum is used to compare all cases characters.

select binary_checksum('a')
select binary_checksum('A')
select checksum('a')
select checksum('A')

Result
97
65
142
142