Asp.Net 4.0 Storing Session in SqlServer

前端 未结 1 671
故里飘歌
故里飘歌 2021-01-01 07:12

I Have Database provided by shared hosting. I want to store the session in sql server but it give me error:

Unable to use SQL Server because ASP.NET version          


        
相关标签:
1条回答
  • 2021-01-01 07:30

    I believe you must have used the aspnet_regsql.exe application which then starts a wizard and then adds various aspnet_* tables to your tables.

    If so then again restart the same wizard and then choose the remove option to remove all those tables from the database.

    Now run this command:

    aspnet_regsql.exe -ssadd -d <Your Database> -sstype c -S <Server> -U <Username> -P <Password>
    

    This will then add two tables to your database, namely ASPStateTempApplications & ASPStateTempSessions.

    Modify your web.config file to include the following configuration:

    <sessionState
        mode="SQLServer"
        allowCustomSqlDatabase="true"
        sqlConnectionString="Data Source=Server;Initial Catalog=Database;User ID=UserId;Password=Password"
        cookieless="false" timeout="20" />
    

    NOTE: 1. I have assumed that you want to store session within your applications database. If you want to maintain the session database separately then run the above command without the "-d" parameter. This will create a new ASPState database with two table that I have specified above. And finally you can specify the name of this database in your configuration.

    Hope this helps :)

    0 讨论(0)
提交回复
热议问题