【发布时间】:2019-08-06 10:47:31
【问题描述】:
我正在尝试连接到 SQL Server。
我正在尝试在 C# 中使用 SqlConnection 对象,我尝试在我的用户名之前放置一个域,我尝试使用和不使用端口号
SqlConnection myConnection = new SqlConnection("user id=username;" +
"password=xxxxx;" +
"server=ipaddress:portnumber;" +
"Trusted_Connection=yes;" +
"database=databaseName; " +
"connection timeout=30");
try
{
myConnection.Open();
}
catch(Exception ex)
{
}
我没有收到任何错误消息,它只是挂在myConnection.Open
【问题讨论】:
-
试试
"server=ipaddress;",或者如果这不起作用,试试"server=ipaddress,portnumber;"- 用逗号(,)分隔IP地址和端口号,不是冒号... -
您将
Trusted_Connection设置为yes,但还传递了用户名和密码的值。这是其中之一;你真的想用哪个? -
@Larnu 不会是
Integrated Security=True? -
Integrated Security和Trusted_Connection是同义词,@Filburt: What is the difference between Trusted_Connection and Integrated Security in a connection string? -
我删除了 Trusted_Connection 行,因为我想使用用户名和密码进行连接。我也尝试过 Marcs 的建议,但它仍然会以相同的方式做出反应并在尝试打开连接时挂起
标签: c# sql-server database sqlconnection