2017-04-06 76 views
0

我知道我的問題是基本的。 但我不知道如何配置web.config信息!連接到ASP中的SQL服務器數據庫

我的SQL服務器與Windows身份驗證連接。 我使用這個配置:

<add key="DBServer" value="mssql" /> 
<add key="DBSource" value="localhost" /> 
<add key="DBName" value="TestDB" /> 
<add key="LoginName" value="KARIM-PC\Karim" /> 
<add key="LoginPWD" value="" /> 

,但我得到這個錯誤:

{"This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection."}

Exception: Thrown: "Login failed for user 'KARIM-PC\Karim'." (System.Data.SqlClient.SqlException) A System.Data.SqlClient.SqlException was thrown: "Login failed for user 'KARIM-PC\Karim'."

回答

1

添加任何<add key="TrustedConnection" value="Yes" /><add key="IntegratedSecurity" value="SSPI" />強制Windows身份驗證。

您可以閱讀更多here

1

對於Windows身份驗證

<add name="MyDbConn" connectionString="Initial Catalog=MyDataBaseNAme;Data Source=MyServerName;Integrated Security=SSPI;"/> 
+0

謝謝。我有這個錯誤:'{「值不能爲空。\ r \ n參數名稱:用戶ID」}' –

+0

在web配置中添加了「用戶ID」的位置? –

+0

'web.config'在這裏:[鏈接](https://github.com/wells-z/CPCMVCMSSQL/blob/master/CoolPrivilegeControl/Web.config) –

1

我建議你這個網站:https://www.connectionstrings.com/sql-server/用於獲取有關連接字符串的詳細信息。 在你的情況下,我認爲它會適合你:

Server=myServerAddress;Database=myDataBase;Trusted_Connection=True; 
+0

OP要求進行窗口身份驗證如何將用戶ID和密碼將連接字符串使用 –

+0

@Sindersindersh,謝謝。我已經更新了我的答案。 – daniell89