<add name="SqlState" connectionString="Data Source=localhost;DataBase=AnyNameOfServerState;Integrated Security=True" providerName="System.Data.SqlClient"/>
<sessionState mode="SQLServer" sqlConnectionString="SqlState" allowCustomSqlDatabase="true" cookieless="false" timeout="20"/>
I tried to put the above two lines into my web.config file and then run the code: I got this:
System.Data.SqlClient.SqlException:
MSDN gives me the following tips:
Verify that you are connecting with valid credentials.
Make sure that the credentials you are supplying are valid. For more information, see How to: Access SQL Server Using Predetermined Credentials.
Verify that the server name is correct and that the server is running.
Make sure that you are using the correct server name, and that the server can be reached.
But I have no idea of how to follow them, cause it is the first time i use Session in SQL mode, ...
More note: I need the session temporarily for a few seconds, I need to save the state for the dynamic controls that i have got. The problem that I think i may encounter with that state mode is if it drags with the user for 20 mins, slowing down my applicat开发者_高级运维ion. Should i use viewState instead?
This is because you need to add the same permission with the asp.net pool to the file that you have create.
Go to your database file and give him (righ click on file, Properties | sercurity) permission read/write to run under the pool user name.
If you automatic made this sql file, then the file is probably is on the *c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data*
If this is not solve it, go also to the SQL database, right click on your database, go the Permissions, and add also the aspnet user of your pool, and give him rights to connect.
精彩评论