Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

Advantages and disadvantages using SQL server session state

With SQL server session state session data is serialized and stored in a database table in the SQL Server database.

Advantages:

1.  If IIS restart session data not affected /application not affected with inProc session we face this issue frequently.
2.  More Secure and reliable compared with InProc and state server.
3.  Usefull in Web farm and Web gardens scenarios.

Disadvantages:

1.  Performance issue is main disadvantage (processing is slow), with SQL server session state application is slow compared with InProc.
2.  Object serialization and de serialization requires crates overhead and network traffic issue.
3.  External configuration required for sql server session state.

Session state modes

ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application.

Example:

//store session value
Session["UserName"] = UsernameTextBox.Text;
//retrieve session value. 
var currentUser= (string)Session["UserName"];

Session state supports three modes:

1.  InProc
2.  State Server
3.  SQL Server

InProc Mode

1. This mode stores the session data in the ASP.NET worker process.
2. This is the fastest among all of the storage modes.
3. This mode effects performance if the amount of data to be stored is large.
4. If ASP.NET worker process recycles or application domain restarts, the session state will be lost.

State Server mode

1. In this mode, the session state is serialized and stored in memory in a separate process.
2. State Server can be maintained on a different system.
3. State Server mode involves overhead since it requires serialization and de-serialization of objects.
4. State Server mode is slower than InProc mode as this stores data in an external process.

SQL Server Mode

In this storage mode, the Session data is serialized and stored in a database table in the SQL Server database.

1. This is reliable and secures storage of a session state.
2. This mode can be used in the web farms.
3. It involves overhead in serialization and de-serialization of the objects.
4. SQL Server is more secure than the InProc or the State server mode.

Advantages and disadvantages of Session


ASP.NET session state enables you to store and retrieve values for a user as the user navigates ASP.NET pages in a Web application.

Example:

//store session value
Session["UserName"] = UsernameTextBox.Text;
//retrieve session value. 
var currentUser= (string)Session["UserName"];


Advantages:

1. It helps maintain user state and data all over the application.
2. It is easy to implement and we can store any kind of object.
3. Stores client data separately.
4. Session is secure and transparent from the user.

Disadvantages:

1. Performance overhead in case of large volumes of data/user, because session data is stored in server memory.

2. Overhead involved in serializing and de-serializing session data, because in the case of StateServer and SQLServer session modes, we need to serialize the objects before storing them.