C# SQLConnection连接错误";用户服务器/来宾登录失败";

C# SQLConnection连接错误";用户服务器/来宾登录失败";,c#,sql-server,authentication,login,sqlconnection,C#,Sql Server,Authentication,Login,Sqlconnection,我一直收到连接错误。我知道这些信息是正确的,因为我在过去几分钟内已经用SSM尝试了好几次,所以问题出在C#连接字符串上。根据各种谷歌搜索,语法是正确的,只是不起作用 try { // Get the connection information. GetSQLConnectInfo(ref sConnect); // Formulate the connection string. String strConnect = String.Format("Serve

我一直收到连接错误。我知道这些信息是正确的,因为我在过去几分钟内已经用SSM尝试了好几次,所以问题出在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
{
}
返回错误:用户“myserver\Guest”登录失败。 错误代码:-2146232060 错误号码:18456

从错误消息来看,Open方法似乎无法识别用户名,因为Open试图使用来宾帐户,这显然不起作用

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
{
}

我错过什么了吗?我正在使用SQL Server身份验证。

删除
Trusted\u Connection=yes
。这将覆盖您的SQL身份验证(用户名/密码)设置,并尝试以运行应用程序的用户身份登录。

您使用的平台是什么?trusted_connection=yes与使用SQL身份验证不匹配。为什么是用户Id而不是用户Id或用户Id?这一点并不明显。我只是借用了我看到的第一个连接字符串之一。我不知道Trusted_连接会覆盖用户名和密码。谢谢如果您发现自己需要再次查找连接字符串,这将是一个很好的资源。我来到这里是为了意识到IIS不允许我的应用程序池使用
Trusted\u connection=yes
进入我的数据库。必须在my
Web.config
中手动输入凭据您需要让Kerberos工作以启用具有多个跃点(客户端-->IIS-->数据库)的受信任连接,这并不简单。它更安全,但更难做到正确。