我在捐贈給我們機構的網站上工作,現在我試圖決定如何在Web.config文件中設置兩個連接字符串(CS)(某些這些連接字符串中的細節由捐贈者編輯)。 的CS我有一個關於中的sessionState被引用的問題:在會話狀態連接字符串中使用什麼賬號
<sessionState allowCustomSqlDatabase="true" mode="SQLServer" sqlConnectionString="DevelopmentSessionState" cookieless="false" timeout="20"/>
我想確定我應該使用什麼類型的賬戶在SessionState的CS的用戶名。爲了使網站正常運行,我使用了sa帳戶,但我知道這不是一個好主意 - 我正在尋找一個帳戶來取代sa。我不知道這是我應該在SQL Server中定義的用戶,還是我應該使用預先存在的帳戶,或者此用戶應具有哪種類型的訪問權限。
我對會話狀態需要單獨連接字符串的理由也很模糊。該網站的C#代碼顯式使用其他CS連接到數據庫,但唯一的SessionState CS引用位於Web.config中。過去幾天,我已經閱讀了很多關於會話狀態和SQLServer模式的內容,但是我還沒有找到有關使用哪個帳戶或SessionState需要單獨CS的原因的建議。
謝謝, 克里斯
更新:這是我代替我的用戶名在會話狀態CS 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身份驗證來避免將系統密碼交給開發人員。 – mjw
謝謝mjw--這對我有很大的幫助。我現在應該可以選擇適當的帳戶。 – Chris