连接到ASP中的SQL服务器数据库

问题描述:

我知道我的问题是基本的。 但我不知道如何配置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'."

添加任何<add key="TrustedConnection" value="Yes" /><add key="IntegratedSecurity" value="SSPI" />强制Windows身份验证。

您可以阅读更多here

对于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) –

我建议你这个网站:https://www.connectionstrings.com/sql-server/用于获取有关连接字符串的详细信息。 在你的情况下,我认为它会适合你:

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

OP要求进行窗口身份验证如何将用户ID和密码将连接字符串使用 –

+0

@Sindersindersh,谢谢。我已经更新了我的答案。 – daniell89