The project I am currently working on involves MS SQL Server and ASP.net Web Services that use Session variables. Apparently this causes a client’s calls to execute in a sequential manner. I want to make sure that these methods execute asynchronously.
After doing some research it appears to me the choicest method is to persist the session state in the database using a table that tracks sessions ( using guids say ) and separate tables for each session.
Before I dive directly into this I need to know if I can gain the same sense of asynchronous operations for the web service if I configure SQL Server to store the session.
Can I ?
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Sorry to say that, but the only way to execute asynchronously your code and use session variables is to make your totally custom session solution – and I mean totally custom and disable the asp.net session entirely.
Basic tips to make your session:
- You have one cookie connected with the users data
- The data is on one table on your database.
- You make custom fields on that table for each session and avoid Dictionary<> to keep them
- You work with Dirty read, last write wins
- You read and write only the session variables that you need each time (not all together)
- Each line have a time out date, and use like MS, a sheduler on SQL to delete old sessions.
- Load session on
OnPreInit, save only what have change on
- By entirely disable the session, you need to lock using
Mutexcode that now is work fine because the session is make synchronization with out notice it, but with out session lock maybe execute two times, like new inserting to database calls.
to answer and to this question
if I configure SQL Server to store the session ? the session is still lock and block the rest request. If you have the session on SQL server or on other medium is not change the way of working, only the place of the saved data.