繁体   English   中英

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

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

我想使用该会话状态,因为Inproc不可靠。 我需要在配置文件中设置该模式,但不知道如何..有人可以帮助我吗?

我从aspnet_regsql工具得到的异常

xception:

无法连接到SQL Server数据库。


故障细节

System.Web.HttpException(0x80004005):无法连接到SQL Server数据库。 ---> System.Data.SqlClient.SqlException(0x80131904):建立与SQL Server的连接时发生与网络相关或特定于实例的错误。 服务器未找到或无法访问。 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (提供者:命名管道提供者,错误: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超时,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 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()

如果您没有在sql上创建会话数据库,则需要首先运行一个使用aspnet_regsql.exe工具创建它的工具。

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

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

其次,您可以使用集成安全性进行连接,而不使用用户名和密码。 在连接字符串上设置

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

转到system.web

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

一些更多的细节。 如果转到网络目录,则会看到带有.sql扩展名的文件列表。 其中之一是InstallSqlState.sql,这是该工具运行以创建数据库的目录。 如果打开它,可以看到正在运行什么。

您也可以使用StateServer。 您可以在此处按照分步指南进行操作

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

我希望您了解每个会话状态的利弊,以便为​​您的应用选择合适的会话。

暂无
暂无

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

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