How to move the session state from InProc to SQLServer

1.9k Views Asked by At

I am currently using InProc session state mode in my .net web project. I want move that from InProc to SQLServer session state as I am going to use a load balancer. What are the steps that I need to follow?

In my C# code, I use as sessions as below.

    Session["MyValue"] = "Test" // To set
    string value = Session["MyValue"] //To read

So what are the changes that I need to do in source code? Can't I use the same code above when using SQLServer session state?

2

There are 2 best solutions below

0
AudioBubble On BEST ANSWER

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

You need to do install the Session State Database Using the Aspnet_regsql.exe Tool and do modifications in your web.config.

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

You really should read carefully throug the already provided articles. They have successfully explained your scenario to several people for years. There is no change to your code necessary, unless you store unserializable data in your session. You should also verify, that you are not storing big amounts of data in your session-state, as SQL-Server session-state - while being more reliable than inproc - is slower.

Another article for your reference: https://support.microsoft.com/en-us/kb/317604