locked
The best way to modify our application from using InProc session state to using SQL server RRS feed

  • Question

  • User747696199 posted

    Hi,

    Our company has an ASP.NET web application that was initially built in 2008, and it uses  session variable extensively, and using "InProc".

    Over the years we have added on a lot of features, many of them continue to use session state "InProc".

    We are looking into the possibility of changing this to using SQL server to store session variables, as Scott Hanselman suggested here: http://www.hanselman.com/blog/TroubleshootingExpiredASPNETSessionStateAndYourOptions.aspx

    Our question is: is there a systematic way, that is simple and complete, that we can modify our application to make this transition?

    Note: our application has both web forms and MVC code; we have dedicated servers, so we do plan to use a dedicated DB for this purpose.

    Any suggestion/advice is appreciated.

    Thanks,

    Claudia

    Sunday, February 14, 2016 9:21 PM

Answers

  • User614698185 posted

    Hi Claudia,

    To use SQLServer mode, you must first be sure the ASP.NET session state database is installed on SQL Server. You can install the ASP.NET session state database using the Aspnet_regsql.exe tool.

    To configure an ASP.NET application to use SQLServer mode, do the following in the application's Web.config file:

    1) Set the mode attribute of the sessionState element to SQLServer.

    2) Set the sqlConnectionString attribute to a connection string for your SQL Server database.

    The following example shows a configuration setting for SQLServer mode where session state is stored on a SQL Server named "SampleSqlServer":

    <configuration>
      <system.web>
        <sessionState mode="SQLServer"
          sqlConnectionString="Integrated Security=SSPI;data 
            source=SampleSqlServer;" />
      </system.web>
    </configuration>

    And for installing the Session State Database using the Aspnet_regsql.exe Tool, please see:

    https://msdn.microsoft.com/en-us/library/ms178586.aspx

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 15, 2016 6:07 AM

All replies

  • User614698185 posted

    Hi Claudia,

    To use SQLServer mode, you must first be sure the ASP.NET session state database is installed on SQL Server. You can install the ASP.NET session state database using the Aspnet_regsql.exe tool.

    To configure an ASP.NET application to use SQLServer mode, do the following in the application's Web.config file:

    1) Set the mode attribute of the sessionState element to SQLServer.

    2) Set the sqlConnectionString attribute to a connection string for your SQL Server database.

    The following example shows a configuration setting for SQLServer mode where session state is stored on a SQL Server named "SampleSqlServer":

    <configuration>
      <system.web>
        <sessionState mode="SQLServer"
          sqlConnectionString="Integrated Security=SSPI;data 
            source=SampleSqlServer;" />
      </system.web>
    </configuration>

    And for installing the Session State Database using the Aspnet_regsql.exe Tool, please see:

    https://msdn.microsoft.com/en-us/library/ms178586.aspx

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 15, 2016 6:07 AM
  • User747696199 posted

    Hi Candice,

    Thanks for your reply.

    1 follow-up question:  Our application uses a lot of session vars; most are simple types, but in some pages, the session vars are complex data types; such as an array, a list, or a data object from a view model.

    How should we handle those, in terms of using SQL Server to store session vars?

    Thanks,

    Claudia

    Friday, February 19, 2016 12:21 AM