Configuring session state on SQL server



There are 2 steps for setting up the ASPState database and the formation setting in your web.config.

you need to use ASP_RegSQl.exe from a command prompt. The script file and the aspregsql EXE are found at
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727.
Formation Steps:
1     Open a command prompt and locate the following path:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727 based on your OS version and .NET version

      Use the following statement:

a.       Using default ASPState database and SQL security
aspnet_regsql -S serverName -U UserName -P Password -ssadd -sstype p

b.       Using default ASPState database and windows security
aspnet_regsql -S serverName -E -ssadd -sstype p

c.       Using custom database and SQL security
aspnet_regsql -d TableName -S serverName -U UserName -P Password -ssadd -sstype c

         1) t - Stores session data in the SQL Server tempdb database. This is the default. If you store session data in the tempdb database, the session data is lost if SQL Server is restarted.

         2)   p - Stores session data in the ASPState database instead of in the tempdb database.

         3)  c - Stores session data in a custom database. If you specify the c option, you must also include the name of the custom database using the -d option.

     In your configuration file [web.config]:

       A) Using default SQL security:

<sessionstate mode="SQLServer" timeout="60" allowcustomsqldatabase="true"
sqlconnectionstring="Data Source=Server;User ID=sa;Password=sa;"
cookieless="false">

      B) Using default windows security:
<sessionstate mode="SQLServer" timeout="60" allowcustomsqldatabase="true"
sqlconnectionstring=" Data Source=Server;Integrated-Security=SSPI;”
cookieless="false">

      C) Custom database name:
<sessionstate mode="SQLServer" timeout="60" allowcustomsqldatabase="true"
sqlconnectionstring=" Data Source=Server; Initial Catalog = tblname; User ID=sa;Password=sa;”
cookieless="false">

NOTE: Things to lookout for when using SQL to store the session info in a web form situation:
    a)  The machine key among the servers' needs to be the same as AspState Session info is encrypted using the machine key.

    b) The application path to your websites on all machines needs to be constant as well.

Why we can't execute a stored procedure from a User Defined function(UDF)

Functions cannot "touch" any database but read them only. Stored procedures can do anything and everything with databases. You ...