SQLServer asp.net session state mode management - Part 66

In this video, we will discuss about the asp.net session state mode - SQLServer. Asp.net session state mode can have any of the following 4 values. Asp.net session state mode is set in web.config file.1. Off - Disables session state for the entire application.2. InProc - Discussed in Part 643. StateServer - Discussed in Part 654. SQLServer - Will be discussed in this session.5. Custom - Enables you to build your own Session State provider. For example, Oracle.

When the session state mode is set to SQLServer, the session state variables are stored in a SQLServer database.

Steps to follow, to configure asp.net web application to use SQLServer:1. Create the ASPState database using aspnet_regsql.exe tool. There are several versions of this tool. I am running .NET version 4.0, on a 64 bit operating system. So I will use the version that is present in C:\Windows\Microsoft.NET\Framework64\v4.0.30319.a) click Start > Type Run > Press Enterb) Type cmd > Press Enterc) In the command prompt type - cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319d) Press Entere) Type - aspnet_regsql.exe -S SQLServerName -E -ssadd -sstype pf) Press Enter. At this point you should have ASPState Database added.g) For help running this tool, please refer to the following MSDN article http://msdn.microsoft.com/en-us/library/ms229862(v=vs.100).aspx

2. Set the Session state mode=SQLServer and sqlConnectionString If you want to use windows authentication<sessionState mode="SQLServer"sqlConnectionString="data source=SQLServerName; integrated security=SSPI"timeout="20"></sessionState>If you want to use sql serevr authentication<sessionState mode="SQLServer"sqlConnectionString="data source=SQLServerName; user id=sa; password=pass"timeout="20"></sessionState>

Advantages of using SQLServer session state mode:1. SQLServer is the most reliable option. Survives worker process recycling and SQL Server restarts.2. Can be used with web farms and web gardens.3. More scalable than State server and InProc session state modes.

Dis-advantages of using StateServer session state mode:1. Slower than StateServer and InProc session state modes2. Complex objects, need to be serialized and deserialized

I am unable to do with User credentials.I have tried by using this code

and In command i have used -E sa -P sql@123 instead of -E and it was excuted succesfull. But i am getting error while cliking the button in the webform1 and the error is "Failed to login to session state SQL server for user 'TENXLABS\satishkumar.g'."

You may have to enable the IIS fromControl Panel\All Control Panel Items\Programs and Features -> Turn Windows Features ON or OFF (from Left panel), and then check the Internet Information Services (IIS).