【问题标题】:How do I properly access my SQL Server database with trusted connection?如何通过受信任的连接正确访问我的 SQL Server 数据库?
【发布时间】:2016-12-06 20:17:11
【问题描述】:
Dim connString As String = "Server=(LocalDB)\MSSQLLocalDB;Database=Database1.mdf;Trusted_Connection=True"

Dim cnn As New SqlConnection(connString)

cnn.Open()

我在我的程序中使用了上面的代码,连接似乎可以工作,但由于某种原因它说

无法打开登录请求的数据库“Database1.mdf”。登录失败。用户“Alex\John”登录失败。

我不知道为什么它不会让我登录,因为我将它设置为受信任。幕后有什么我想念的吗?

【问题讨论】:

  • 不,谢谢。认为另一个人离我更近,没有链接服务器。
  • 那么,您没有使用 LocalDB 吗?您是否在名为“Alex”的服务器上使用作为服务运行的 SQL Server?您是否尝试从另一台 PC 或同一台 PC 连接?您的 PC 是域的成员吗?
  • 你的服务器的服务器认证方式是什么?如果是 Windows 身份验证,您不需要传递用户名和密码,但您的电脑使用的帐户必须存在于服务器中,您才能连接到它。而如果是sql server auth,则需要传递sql server中Logins节点下存在的用户名和密码。

标签: sql-server vb.net localdb


【解决方案1】:

您正在连接到mdf。也就是数据库文件,需要连接服务器

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

Sql Connection Strings

【讨论】:

  • 我如何知道服务器输入是什么?我有一个名为 Alex 的服务器,但我无法连接到它。
【解决方案2】:
connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Database1.mdf;Data Source=Alex-PC;"

connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Database;Data Source=Alex-PC

【讨论】:

  • 这假设数据库启用了基于 Windows 的授权,或者您要连接的任何数据库都具有登录权限。
  • 我建议连接到数据库而不是调用 .mdf。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-10-22
  • 2012-03-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多