skip to Main Content

I restored a Database and I created a session state through this command

     -ssadd -sstype p -S IP_ADDRESS -U USER_ID sa1 -P USER_PASS

And in my web.config I have the following:

<sessionState mode="SQLServer" allowCustomSqlDatabase="true" 
        sqlConnectionString="Data Source=IP_ADDRESS;User Id=USER_ID;Password=USER_PASSWORD" cookieless="false" timeout="35"/>

I am using IIS to host the website. I noticed that there is Session State configuration there, and it is using InProcess Mode. Do I need to update the Session State in the IIS, or is my Web.config already enough?

I am getting erratic session expiry, and I am not sure what’s causing the session expiry. Please help a newbie out, the docs I found on the internet is very confusing. TIA!

IIS Session State Settings



  1. What you see in IIS should reflect what you have in your web.config file.

    However, most settings can be set at the server level and overridden at the website level. So are you sure you’re looking in the right place for your website?

    I haven’t worked in IIS much over the past year and my memory is fading, but I think it’s most likely that you are just looking at the configuration at a higher level rather than what the configuration is for this particular website.

    Login or Signup to reply.
  2. Yes, you have to change the above settings you have.

    You are to select SQL server in your screen shot.

    enter image description here

    And in most cases, you should check the "allow custom database".

    When you change the above, then web config should result in something like this:

    <sessionState allowCustomSqlDatabase="true" 
          mode="SQLServer" sqlConnectionString="ASPState">

    So, assuming you have setup the connection string in your web config, then the dropdown in IIS should have that connection string setting you have. If not, then you can use the create connection, and it will of course then modify web.config for you.

    So, in your web.config connection strings area, you need to have a connection string setup for the ASPState database.


    <add name="ASPState" 
    connectionString="Data Source=XX.XX.XXX.XXXXSQLEXPRESS,database=ASPState;
    providerName="System.Data.SqlClient" />

    (above connection is on one line – above for ease of reading).

    Also, keep in mind, that if you launch SQL manager you will note that while a ASPState database is created?

    The session tables are created, used, and run as temp tables and are actually placed in system "tempdb" database!

    This can be rather confusing, since if you re boot SQL server, then all tempdb databases are deleted. However, in the ASPState database, you find some stored procedures that run on server startup that re-creates the session database. So, this is just a FYI, since it can be confusing that a ASPState database is created, but the actual session tables are created and used from the system "tempdb" database and NOT the ASPState database.

    The other issue of course is if you are using SQL Server "express" or are you using the full edition of SQL server?

    This matters, since the "express" edition does not include the so-called SQL "agent" which is used to automatic run scheduled tasks by SQL server. Those tasks include clearing out of the session database every 10 minutes, or some such.

    So, this means if you are using SQL server express, then the automated cleaning out and deleting of session rows (in that tempdb) does not occur. This suggests that you have to setup your own scheduled task (say using windows scheduler) to delete and clean out the session database (I suggest a daily routine to do this). So, keep in mind 2 things that are confusing:

    While a ASPState database is created when you run that script, the actual session tables used are created in tempdb.

    If you re-boot SQL server, then tempdb is cleared out, and hence the session tables are also deleted.

    However, in ASPState, there are some stored procedures setup to run on SQL server startup to re-create the session tables. This works fine for both SQL server, and including the SQL express edition.

    However, since SQL express does not have the SQL "agent" built in, then you need to setup your own scheduled task to clear out the session tables (else they will grow rather large without the session rows being automatic deleted).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top