为什么我不能通过连接字符串连接到数据库?

时间:2014-12-07 06:20:58

标签: c# sql-server connection-string

我在本地网络上有一个数据库。

我可以在SSMS中连接到数据库:

enter image description here

但是当我想通过c#中的这个连接字符串连接到数据库时:

"Data Source=192.168.0.3,14330;Network Library=DBMSSOCN;Initial Catalog=master;Integrated Security=True;User ID=sa;Password=123456789;"

我收到以下错误:

  

登录失败。登录来自不受信任的域,不能与Windows身份验证一起使用。

1 个答案:

答案 0 :(得分:2)

您告诉sql server使用集成安全性,即Windows安全性,但是您尝试使用用户名和密码

关闭集成安全性,请参阅以下示例

"Data Source=192.168.0.3,14330;Network Library=DBMSSOCN;Initial Catalog=master;Integrated Security=False;User ID=sa;Password=123456789;"

相关信息

如果指定了用户ID和密码且Integrated Security设置为true,则将忽略用户ID和密码,并将使用Integrated Security。

您可以在此处找到有关连接字符串的更多信息,SqlConnection.ConnectionString Property

<强>更新

也许这个问题可能对您有所帮助How to get the connection String from a database

更新2

有关更深入的问题排查,这里有一个很好的资源How to Troubleshoot Connecting to the SQL Server Database Engine

相关问题