简体   繁体   English

如何使用会话状态模式:带有VS2010的SQL Server

[英]How to use Session state mode : SQL Server with VS2010

I want to use that session state, because Inproc is unreliable. 我想使用该会话状态,因为Inproc不可靠。 I need to set that mode in the config file, but dont know how.. can someone help me? 我需要在配置文件中设置该模式,但不知道如何..有人可以帮助我吗?

Exception i got from aspnet_regsql tool 我从aspnet_regsql工具得到的异常

xception:

Unable to connect to SQL Server database. 无法连接到SQL Server数据库。


Details of failure 故障细节

System.Web.HttpException (0x80004005): Unable to connect to SQL Server database. System.Web.HttpException(0x80004005):无法连接到SQL Server数据库。 ---> System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. ---> System.Data.SqlClient.SqlException(0x80131904):建立与SQL Server的连接时发生与网络相关或特定于实例的错误。 The server was not found or was not accessible. 服务器未找到或无法访问。 Verify that the instance name is correct and that SQL Server is configured to allow remote connections. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity) at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, SqlConnection owningObject) at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout) at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, TimeoutTim (提供者:命名管道提供者,错误:40-无法打开与SQL Server的连接)位于System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()处,位于System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔值BreakConnection)。 System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo,字符串newPasswordOpen,BooleanSimpleSystem.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo,SqlInternalConnectionTds connHandler,布尔ignoreSniOpenTimeout,Int64 timerExpire,布尔加密,布尔trustServerCert,布尔IntegratedSecurity) ,System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo,String newPassword,Boolean redirectedUserInstance,SqlConnection owningObject,SqlConnectionString connectionOptions,TimeoutTimer timeout)在System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(超时时间 er timeout, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection er超时,System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity身份,SqlConnectionString connectionOptions,Object providerInfo,String newPassword,SqlConnectionString connectionOptions,String newPassword,布尔Boolean redirectedUserInstance)在System.Data.SqlClient.SqlConnectionFactory System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection,DbConnectionPool池,DbConnectionOptions选项).System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)处的。 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owneringObject)的System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) at System.Data.SqlClient.SqlConnection.Open() at System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) at System.Web.Management.SqlServices.GetSqlConnection(String server, String user, String password, Boolean trusted, String connectionString) at System.Web.Management.SqlServices.SetupApplicationServices(String server, String user, String password, Boolean trusted, String connectionString, String database, String dbFileName, SqlFeatures features, Boolean install) at System.Web.Management.ConfirmPanel.Execute() System.Data.ProviderBase.DbConnectionClosed.OpenConnection上的owningConnection)(System.Data.SqlClient.SqlConnection.Open()上System.Web.Management.SqlServices.GetSqlConnection(DbConnection externalConnection,DbConnectionFactory connectionFactory)(String server,String user,String password ,位于System.Web.Management.SqlServices.GetSqlConnection(字符串服务器,字符串用户,字符串用户,字符串密码,布尔值可信,字符串connectionString),位于System.Web.Manage.SqlServices.SetupApplicationServices(字符串服务器,字符串用户,字符串密码,布尔值可信,字符串连接字符串,字符串数据库,字符串dbFileName,SqlFeatures功能,布尔值安装),位于System.Web.Management.ConfirmPanel.Execute()

If you do not have create on sql the session database you need first to run a tool to create it using the aspnet_regsql.exe tool. 如果您没有在sql上创建会话数据库,则需要首先运行一个使用aspnet_regsql.exe工具创建它的工具。

DATABASENAME = AnyNameOfServerState
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727>aspnet_regsql.exe -ssadd -sstype c -d DATABASENAME -E

More for this tool: http://msdn.microsoft.com/en-us/library/ms229862(VS.80).aspx 此工具的更多信息: http : //msdn.microsoft.com/zh-cn/library/ms229862(VS.80).aspx

Second you can connect using Integrated security and not use user name and password. 其次,您可以使用集成安全性进行连接,而不使用用户名和密码。 Set this on connection strings 在连接字符串上设置

<add name="SqlState" connectionString="Data Source=localhost;DataBase=AnyNameOfServerState;Integrated Security=True" providerName="System.Data.SqlClient"/>

This go to system.web 转到system.web

<sessionState mode="SQLServer" sqlConnectionString="SqlState" allowCustomSqlDatabase="true" cookieless="false" timeout="20"/>

Some more details. 一些更多的细节。 If you go to your net directory you see a list of files with .sql extention. 如果转到网络目录,则会看到带有.sql扩展名的文件列表。 One of this is the InstallSqlState.sql, this is the one that the tool runs to create the database. 其中之一是InstallSqlState.sql,这是该工具运行以创建数据库的目录。 If you open it you can see what is run. 如果打开它,可以看到正在运行什么。

You can also use a StateServer. 您也可以使用StateServer。 You can following the step-by-step guide here 您可以在此处按照分步指南进行操作

http://dotnetguts.blogspot.com/2009/06/steps-for-session-inproc-mode-to.html http://dotnetguts.blogspot.com/2009/06/steps-for-session-inproc-mode-to.html

I hope you know the pro/cons of each of the session states so you can choose the right one for your application. 我希望您了解每个会话状态的利弊,以便为​​您的应用选择合适的会话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM