Enable ASP.NET SQL Server Session on your web application yourself

Databases > MS SQL 2008
Please follow the steps below to enable ASP.NET SQL Server Session on your web application yourself.

1. Create a database in your local for storing the session.

2.General speaking, you can find InstallSqlStateTemplate.sql in C:\Windows\Microsoft.NET\Framework\version_ID\, for example C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallSqlStateTemplate.sql, copy it to a new folder and edit it, replace the strings of 'DatabaseNamePlaceHolder' to the database you just created in your local.

3. Login to the database you just created with SQL management studio, copy the query from the new InstallSqlStateTemplate.sql, and execute it in the database. You will get the result below
-------------------------------------------------
    Starting execution of InstallSqlStateTemplate.SQL
    -------------------------------------------------
      
    --------------------------------------------------
    Note:                                           
    This file is included for backward compatibility
    only.  You should use aspnet_regsql.exe to install
    and uninstall SQL session state.                
      
    Run 'aspnet_regsql.exe -?' for details.       
    --------------------------------------------------
    If the job does not exist, an error from msdb.dbo.sp_delete_job is expected.
    Msg 229, Level 14, State 5, Procedure sp_delete_job, Line 1
    The EXECUTE permission was denied on the object 'sp_delete_job', database 'msdb', schema 'dbo'.
    If the category already exists, an error from msdb.dbo.sp_add_category is expected.
    Msg 229, Level 14, State 5, Procedure sp_add_category, Line 1
    The EXECUTE permission was denied on the object 'sp_add_category', database 'msdb', schema 'dbo'.
    Msg 229, Level 14, State 5, Procedure sp_add_job, Line 1
    The EXECUTE permission was denied on the object 'sp_add_job', database 'msdb', schema 'dbo'.
      
    --------------------------------------------------
    Completed execution of InstallSqlStateTemplate.SQL
    --------------------------------------------------
The error is because the database user does create the schedule job to delete the expired 'session', but the needed tables and procedures are installed to your database already.
 
Note: You can also use below command to install SQL Server State:
 
aspnet_regsql.exe -S <SQL Server IP> -U <User Name> -P <Password>  -ssadd -sstype c -d <Database Name>


4. Backup this database and upload the backup file to your hosting account DB folder with us.

5. Login to your hosting control panel -->Database manager-->MSSQL manager to create a new database and restore it backup file, please click here for details

6. Update your web.config file to use sql database to store the session, add the code below to web.config file
< sessionState
  mode="SQLServer"
  allowCustomSqlDatabase = "true"
  sqlConnectionString="data Source=<SQLSERVERNAME>;database=<SQLDATABASENAME>;user id=<SQLUSER>;password=<SQLPASSWORD>"
  cookieless="false"
  timeout="15"
/>
** Use mode = SQLServer
** To use custom DB instead of default database "ASPSTATE" , need to enable option allowCustomSqlDatabase="true"
** sessionState : S is uppercase, it is case sensitive here
** sqlConnectionString :  C , S are uppercase, here is case sensitive

7. Now when you run your site, you will find the session stored in your database.