Sar*_*ger 2 c# sql-server authentication login sqlconnection
我一直收到连接错误.我知道这些信息是正确的,因为我在最后几分钟内已经多次尝试使用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
{
}
Run Code Online (Sandbox Code Playgroud)
错误返回:用户'myserver\Guest'登录失败.错误代码:-2146232060错误号码:18456
似乎从错误消息判断,Open方法无法识别用户名,因为Open尝试使用来宾帐户,这显然不起作用.
我错过了什么吗?我正在使用SQL Server身份验证.