Store the session value in SQL Server.

Source: Internet
Author: User
Tags sql server query

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.