1

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dumi
  • 1,414
  • 4
  • 21
  • 41
  • Entirely depends on how careful you've been in using session state up until now. If everything you've placed in the session is serializable then changing it should be trivial. OTOH, if you've been storing complex, non-serializable objects in the session, you'll have a fair bit of work to do to eliminate/replace those. – Damien_The_Unbeliever Dec 12 '16 at 15:29
  • 1
    Have you tried to google? The first result is from msdn, and explain how to do it: https://msdn.microsoft.com/en-us/library/ms178586.aspx – Ricardo Pontual Dec 12 '16 at 15:31
  • You can use the same code without any problem when switch to SQL server session state, only changes is your web.config setting – Tony Dong Dec 12 '16 at 17:28

2 Answers2

0

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

K. Berger
  • 361
  • 1
  • 9
0

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>