Introduction
This article is a continuation of my previous article on Storing Sessions in a State Server.
I would request readers to have a quick look at my previous article here: Out-of-Process Session State (In State Server) in ASP.NET
In ASP.Net, by default sessions are stored in-proc (i.e. in memory of the Web Server).
Sessions can be stored out-of-process
- In a local or remote NT Service
- In a local or remote SQL Server.
Let us understand how sessions can be stored in a SQL Server with a sample demo.
To begin with, please download the sample code (OutofProcSessionState.zip) from: Out-of-Process Session State (In State Server) in ASP.NET
Step 1. Open the project.
Step 2. Go to the Web. Config file:
- We need to change the SessionState mode to "SQL Server" and also need to provide the corresponding SQLConnection String as shown below:
<sessionStatemode="SQLServer" sqlConnectionString="server=SAURABHPC;trusted_connection=yes"</sessionState> - Note that the SQL connection string will vary in your case.
Step 3. Now, go to Login.aspx and run the application from Visual Studio.

Step 4. Click "Go to Home Page" (as per the logic mentioned; the user should go to the new page (Home.aspx) and the user name "Gaurav Singh" should be retrieved from the session.

Step 5. Not a good-looking screen for developers!! Right… Let's sort it out!!
Step 6. As the error screen says, it was unable to open a particular database (ASPState) in the SQL Server name "Saurabh-PC" which we specified in the web. config.
Step 7. So, what we need to do is to open a Visual Studio Command Prompt to configure the database, as in:








prakash namPosted Mar 17, 2013, 6:10 AM
is really good.. .