In general, we like to use session to store our variables. ASP. NET provides the following methods to store session values:
Inproc
State Server
SQL Server
"Inproc" indicates that we store the session value in the same way as traditional ASP, and "State server" indicates that we use another host to store the session value. Of course, we can also use SQL Server to store values. This article is dedicated to explaining this method.
Run the installsqlstate. SQL File
Find the installsqlstate. SQL file in winnt \ Microsoft. NET and execute it in SQL Server. On my machine, it exists in the E: \ winnt \ Microsoft. NET \ framework \ v1.0.2914 \ directory. This file is provided by Microsoft and contains a wide range of SQL statements. Modify your web. config file and set the session mode to SQL Server.
Change the sessionstate section of Web. config:
<Sessionstate mode = "sqlserver" sqlconnectionstring = "Data Source = Win2000; userid = sa; Password =" cookieless = "false" timeout = "20"/>
Create ASP. NET web forms
Now all session variables are stored in the data table, rather than in the memory. You can open the aspstatetempsessions table to view the session data.
Delete these databases and tables
If you don't like the data storage method, you can delete the tables and databases. Do not worry that such deletion will affect the database (because you are afraid to delete some data by mistake), because Microsoft also has to provide you with a delete SQL file named unintallsqlstate. SQL. It is placed in the config directory of. net like intallsqlstate. SQL.
In addition:
2. Stored in Windows Services
Start Asp.net State Service (Net start aspnet_state)
Modify web. config
<Configuration>
<System. Web>
<Sessionstate mode = "StateServer"
Stateconnectionstring = "TCPIP = Wagner. 0.0.1: 42424"/>
</System. Web>
</Configuration>
3. stored in the database
Run installsqlstate. SQL in Microsoft SQL Server Query analyzer. Find this file under "C: \ winnt \ Microsoft. NET \ framework \ v1.1.4322 ".
Modify web. config
<Configuration>
<System. Web>
<Sessionstate
Mode = "sqlserver"
Sqlconnectionstring = "Data Source =.; user id = sa; Password = 135"
Cookieless = "false"
Timeout = "20"/>
</System. Web>
</Configuration>
Restart the SQL Server and SQL Server Agent services.
You can use the following SQL statement to query sessions.
Select * From aspstatetempsessions