I have an object that I keep in session. This object needs to be updated when some job is done, so it has a timer (I am using ThreadPool.RegisterWaitForSingleObject) to check if this job has done yet.
This code works great when using `sessionState mode="InProc" ,` but when using `sessionState mode="SQLServer"` the object simply does not being updated.
Can anyone explain why this problem occurs? Can anyone suggest a solution or some workaround?
This code works great when using `sessionState mode="InProc" ,` but when using `sessionState mode="SQLServer"` the object simply does not being updated.
Hi,
When you set sessionState with the InProc mode the data is stored in the memory. If you restart your computer the data will be lost. I suppose this may be the reason you use SQLServer mode. However, when you use the SQLServer mode you may need to install
the session state database on your SQL Server. You can install it with the Aspnet_regsql.exe tool. Furthermore you should set sessionstate=SQLServer in your web.config file. And you should set the sqlConnectionString attritube to the connection string for
your SQL Server database. The reason of your object doesn’t being updated may due to the session fails to connect to the database.
You can refer to the below link about session state mode.
Everything is configured correctly and works perfectly unless custom thread is created. For custom thread it seems like the Session is not available anymore and the work is done on some deep cloned object.
basdanny
Member
4 Points
3 Posts
Session is not updated for custom thread when using sessionState mode "SQLServer"
Dec 12, 2011 08:13 AM|LINK
I have an object that I keep in session. This object needs to be updated when some job is done, so it has a timer (I am using ThreadPool.RegisterWaitForSingleObject) to check if this job has done yet.
This code works great when using `sessionState mode="InProc" ,` but when using `sessionState mode="SQLServer"` the object simply does not being updated.
Can anyone explain why this problem occurs? Can anyone suggest a solution or some workaround?
Qi Wu - MSFT
Contributor
5794 Points
677 Posts
Re: Session is not updated for custom thread when using sessionState mode "SQLServer"
Dec 14, 2011 04:42 AM|LINK
Hi,
When you set sessionState with the InProc mode the data is stored in the memory. If you restart your computer the data will be lost. I suppose this may be the reason you use SQLServer mode. However, when you use the SQLServer mode you may need to install the session state database on your SQL Server. You can install it with the Aspnet_regsql.exe tool. Furthermore you should set sessionstate=SQLServer in your web.config file. And you should set the sqlConnectionString attritube to the connection string for your SQL Server database. The reason of your object doesn’t being updated may due to the session fails to connect to the database.
You can refer to the below link about session state mode.
http://msdn.microsoft.com/en-us/library/ms178586.aspx
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
basdanny
Member
4 Points
3 Posts
Re: Session is not updated for custom thread when using sessionState mode "SQLServer"
Dec 14, 2011 07:54 AM|LINK
I familiar with the session state 'SQLServer'.
Everything is configured correctly and works perfectly unless custom thread is created. For custom thread it seems like the Session is not available anymore and the work is done on some deep cloned object.
basdanny
Member
4 Points
3 Posts
Re: Session is not updated for custom thread when using sessionState mode "SQLServer"
Dec 16, 2011 07:05 PM|LINK
It seems the issue is known.
Found several threads about it (below). No resolution though.
http://stackoverflow.com/questions/8519780/asp-net-session-and-thread-issue
http://forums.asp.net/t/1681945.aspx/1?SQL+Session+State+and+Keep+session+value+in+Multithreading
http://bytes.com/topic/asp-net/answers/294573-session-state-does-not-work-multithreading-sql-server-bug