【发布时间】:2015-08-28 15:36:34
【问题描述】:
我正在开发一个捐赠给我们机构的网站,现在我正在尝试确定如何在 Web.config 文件中设置两个连接字符串 (CS)(这些连接字符串中的一些详细信息)由捐赠者编辑)。 我有疑问的 CS 在 sessionState 中引用:
<sessionState allowCustomSqlDatabase="true" mode="SQLServer" sqlConnectionString="DevelopmentSessionState" cookieless="false" timeout="20"/>
我正在尝试确定应该为 SessionState CS 中的 UserID 使用哪种类型的帐户。为了使网站正常运行,我使用了 sa 帐户,但我知道这不是一个好主意 - 我正在寻找一个帐户来替换 sa。我不知道这是否是我应该在 SQL Server 中定义的用户,或者我是否应该使用预先存在的帐户,或者该用户应该拥有什么类型的访问权限。
我也不清楚为什么会话状态需要单独的连接字符串。网站的 c# 代码显式使用其他 CS 连接到数据库,但对 SessionState CS 的唯一引用是在 Web.config 中。在过去的几天里,我阅读了很多关于 Session State 和 SQLServer 模式的信息,但是我没有找到任何关于使用什么帐户或为什么 SessionState 需要单独的 CS 的建议。
谢谢, 克里斯
更新:这是我在会话状态 CS 中用我的 UserID 替换 sa 时发生的异常结束的堆栈跟踪(我用 USERID 替换了我的实际用户 ID):
Server Error in '/' Application.
Failed to login to session state SQL server for user 'USERID'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Failed to login to session state SQL server for user 'USERID'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[SqlException (0x80131904): Login failed for user 'USERID'.]
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4876535
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1121
System.Data.SqlClient.SqlInternalConnectionTds.CompleteLogin(Boolean enlistOK) +35
System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject) +144
System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart) +367
System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance) +225
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance) +189
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection) +185
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options) +31
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject) +431
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject) +66
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +499
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +65
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.SqlClient.SqlConnection.Open() +122
System.Web.SessionState.SqlStateConnection..ctor(SqlPartitionInfo sqlPartitionInfo) +93
[HttpException (0x80004005): Failed to login to session state SQL server for user 'USERID'.]
Version Information: Microsoft .NET Framework Version:2.0.50727.5485; ASP.NET Version:2.0.50727.5491
【问题讨论】:
-
通常您可以在多个应用程序之间共享 sessionState 数据库,因此拥有一个帐户是一种公认的做法。无论您选择使用 SQL 还是集成 Windows 身份验证都是您应该权衡组织的整体战略的设计选择。例如,某些环境更喜欢使用 Windows Auth 以避免将系统密码交到开发人员手中。
-
感谢 mjw - 这很有帮助。我现在应该可以选择合适的帐户了。
标签: c# asp.net session-state