How to: Configure SQL Server to store ASP. NET session state

Source: Internet
Author: User
How to: Configure SQL Server to store ASP. NET session state

Applicable

This article was previusly published under q317604

In this task
  • Summary
    • Requirements
    • Configure SQL Server for ASP. net SQL Server session state
    • Modify the Web. config file of your application
    • Troubleshooting
  • References

Summary

This step-by-step article demonstrates how to configure Microsoft SQL Server for ASP. net SQL SERVER mode session state management.

Back to the top

Requirements

The following list outlines the recommended hardware, software, network infrastructure, and service packs that you need:

  • Microsoft Windows 2000 Professional, Microsoft Windows 2000 Server, Microsoft Windows 2000 Advanced Server, or Microsoft Windows XP
  • Microsoft. NET Framework
  • Microsoft Internet Information Services (IIS)
  • Microsoft SQL Server

Back to the top

Configure SQL Server for ASP. net SQL Server session state

The following steps describe how to run the installsqlstate. SQL and the uninstallsqlstate. SQL script files to configure SQL SERVER mode session state management.

  1. In SQL query analyzer, onFileMenu, clickOpen.
  2. InOpen Query fileDialog box, browse to the installsqlstate. SQL script file, and then clickOpen. 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, clickExecuteOnQueryMenu 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:
    1. On the windowsStartMenu, clickRun, TypeCMD, And then clickOKTo open a command prompt.
    2. At the command prompt, typeNet stop w3svc. You receive confirmation that the w3svc process is stopped.
  5. In SQL query analyzer, onFileMenu, clickOpen.
  6. InOpen Query fileDialog box, browse to the uninstallsqlstate. SQL script file, and then clickOpen. 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/

  7. After uninstallsqlstate. SQL opens in SQL query analyzer, clickExecuteOnQueryMenu to run the script.
  8. After you uninstall SQL SERVER mode session state management configuration, you must restart the w3svc service. to restart the w3svc process, TypeNet start w3svcAt a command prompt.

Back to the top

Modify the Web. config file of your application

To implement ASP. net SQL SERVER mode session State management, you must modify<Sessionstate>Element of your application's web. config file as follows:

  1. SetModeAttribute of<Sessionstate>ElementSqlserverTo indicate that session state is stored in SQL Server.
  2. SetSqlconnectionstringAttribute to specify the connection string for SQL Server. For example:
    sqlConnectionString="data source=MySQLServer;user id=<username>;password=<strongpassword>"

    NoteThe user, <User Name>, must have permissions to perform this operation on the database.

    The modified<Sessionstate>Element shoshould appear as follows:

    <sessionState             mode="SQLServer"            sqlConnectionString="data source=127.0.0.1;user id=<username>;password=<strongpassword>"            cookieless="false"             timeout="20"     />

    NoteEnsure that you use the correct case when you specify<Sessionstate>Element and the associated attribute values. This code is case sensitive.

Back to the top

Troubleshooting
  • If you do not stop the w3svc process before you run the uninstallsqlstate. SQL script file, you receive the following error message: cannot drop the database 'aspstate' because it is currently in use
  • If entries inAspstatetempsessionsTable are not removed after the related sessions expire, make sure that the SQL Server Agent is running. you can implement this functionality through stored procedures that are scheduled through jobs in SQL Server. the SQL Server Agent manages these jobs.
  • When you use the default installsqlstate. SQL and uninstallsqlstate. SQL script files to configure ASP. net SQL SERVER mode session State management, note that these files AddAspstatetempsessionsAndAspstatetempapplicationsTables toTempdbDatabase in SQL Server by default. Furthermore, if you restart SQL Server, you lose the session state data that was stored inAspstatetempsessionsAndAspstatetempapplicationsTables. for additional information about how to run alternative scripts to configure persistent SQL Server session state management so that the session data is not lost when you restart the server, click the article number below to view the article in the Microsoft Knowledge Base:
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.