I keep receiving a connection error. I know that the information is right, as I tried them out with SSMS now several times in the last few minutes, so the problem is in the C# connection string. According to various Google searches, the syntax is right, just it does not work.
我一直收到一个连接错误。我知道这些信息是正确的,因为我在过去几分钟内已经多次尝试使用SSMS,所以问题出现在c#连接字符串中。根据各种谷歌搜索,语法是对的,只是它不起作用。
try
{
// Get the connection information.
GetSQLConnectInfo(ref sConnect);
// Formulate the connection string.
String strConnect = String.Format("Server=myserver;Database=mydb;User Id=myusername;Password=mypassword;Trusted_Connection=yes;connection timeout=30");
// DATABASE: Create the connection.
SqlConnection oConnection = new SqlConnection(strConnect);
oConnection.Open();
if (ConnectionState.Open != oConnection.State)
return false;
return true;
}
catch
{
}
Error comes back with: Login failed for user 'myserver\Guest'. Error Code: -2146232060 Error Number: 18456
错误返回:用户“myserver my\ Guest”登录失败。错误代码:-2146232060错误号:18456
It would seem that judging by the error message, the Open method does not recognize the user name, as Open tries to use a guest account, which obviusly will not work.
从错误消息判断,Open方法似乎不认识用户名,因为Open试图使用来宾帐户,这显然行不通。
Am I missing something? I am using SQL Server authentication.
我遗漏了什么东西?我正在使用SQL Server身份验证。
1 个解决方案
#1
5
Remove Trusted_Connection=yes
. That will override your SQL Authentication (username/password) settings and try to log in as the user running the app.
删除Trusted_Connection = yes。这将覆盖您的SQL身份验证(用户名/密码)设置,并尝试作为运行应用程序的用户登录。
#1
5
Remove Trusted_Connection=yes
. That will override your SQL Authentication (username/password) settings and try to log in as the user running the app.
删除Trusted_Connection = yes。这将覆盖您的SQL身份验证(用户名/密码)设置,并尝试作为运行应用程序的用户登录。