Using SQL Server To Maintain Session State
Using SQL Server To Maintain Session State
Using SQL Server To Maintain Session State
2.
In the Open Query File dialog box, browse to the InstallSqlState.sql script file, and then click Open. By
default, InstallSqlState.sql is located in one of the following folders:
system drive\WINNT\Microsoft.NET\Framework\version\
system drive\Windows\Microsoft.NET\Framework\version\
3.
After InstallSqlState.sql opens in SQL Query Analyzer, click Execute on the Query menu to run the script.
4.
Before you run the UninstallSqlState.sql script file to uninstall SQL Server mode session state management
configuration, you must stop the w3svc process. To do this, follow these steps:
a.
On the Windows Start menu, click Run, type cmd, and then click OK to open a command prompt.
b.
At the command prompt, type net stop w3svc. You receive confirmation that the w3svc process is
stopped.
2.
3.
In the Open Query File dialog box, browse to the UninstallSqlState.sql script file, and then click Open. By
default, UninstallSqlState.sql is located in one of the following folders:
system drive\WINNT\Microsoft.NET\Framework\version\
system drive\Windows\Microsoft.NET\Framework\version\
4.
After UninstallSqlState.sql opens in SQL Query Analyzer, click Execute on the Query menu to run the
script.
5.
After you uninstall SQL Server mode session state management configuration, you must restart the w3svc
service. To restart the w3svc process, type net start w3svc at a command prompt.
1.
Set the mode attribute of the <sessionState> element to SQLServer to indicate that session state is
stored in SQL Server.
2.
Set the sqlConnectionString attribute to specify the connection string for SQL Server. For example:
3.
sqlConnectionString="data source=MySQLServer;user
id=<username>;password=<strongpassword>"
Note The user, <user name>, must have permissions to perform this operation on the database.
<sessionState
mode="SQLServer"
sqlConnectionString="data source=127.0.0.1;user
id=<username>;password=<strongpassword>"
cookieless="false"
timeout="20"
/>
USING the StateServer database for sessions:
InProc--store in memory. This is the fastest for performance, but all data is lost
when the ASP.NET process recycles.
SQLServer--store data on SQL Server. This is the most reliable since it's
disconnected from the Web server. This option uses the sqlConnectionString option.
The connection string follows the normal syntax for connecting to a SQL Server
database.
StateServer--store data on a separate Web server (IIS). This option uses the
stateConnectionString attribute.
All options use the remaining. The cookieless attributes signal whether cookies are
stored in memory (false) or maintained in the QueryString/URL (true). The timeout
attribute signals the length of time (without activity) that session variables are stored.
Now let's turn our attention to SQL Server setup.
SQL Server setup
SQL Server requires a special database to handle state management. Thankfully, the
.NET Framework installation includes the necessary files to get this up and running in
no time. The following scripts are installed: