Intro. One of our subscription websites saves quite a bit of information in Session variables. This website is now ready to go to beta test, so it is time to change the session state mode from the default InProc which stores Session variables in memory to SQLServer which stores Session variables in a sql database.
The Problem. I followed the instructions I found on msdn.microsoft.com, but that resulted in several errors sending me to google to search for possible solutions. One error that I got was:
Failed to login to session state SQL server for user 'TESTSERVER\ASPNET'
where TestServer is our test webpage server. This error reminded me that TestServer is using IIS 5, so I moved the test to our production webpage server, Laurel, which is running IIS 6. The new error was:
Failed to login to session state SQL server for user 'NT AUTHORITY\NETWORK SERVICE'
That's the IIS 6 error, and it was solved by setting up the sessionState tag correctly, as shown below.
The Solution. Here are the steps that worked for me. Note this usage: our webpage server is Laurel, sql database server is Hardy, MyUser is an existing user on Hardy with db_owner access to the databases used by the new website, MyPass is MyUser's password. Also note that our web.config does not use impersonation and that our authentication mode="Forms".
1. Open a command window on Laurel, change directories, and run the setup:
cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
aspnet_regsql.exe -S Hardy -E -ssadd
This created a database on Hardy named ASPState which contains all the stored procedures needed to do SQLServer session state. The data will actually be stored in tempdb, a system database.
2. We already had this in the web.config within the system.web and configuration tags:
< sessionState timeout="60" />
So, I changed it to:
< sessionState timeout="60" mode="SQLServer" sqlConnectionString="Data Source=HARDY;User Id=MyUser;Password=MyPass;" />
3. I used SQL Server Management Studio on Hardy to go to Security | Logins | MyUser | Properties | User Mapping. I checked the boxes for ASPState and db_owner, and tempdb and db_owner, and clicked OK.
I browsed to the webpage and everything worked fine.