SQLConnection connection error "Login failed for user server/guest"

11,072

Remove Trusted_Connection=yes. That will override your SQL Authentication (username/password) settings and try to log in as the user running the app.

Share:
11,072
Sarah Weinberger
Author by

Sarah Weinberger

Connect with me on LinkedIn and Facebook, and follow me on Twitter. Software and Systems Engineering Consulting Services C#.Net, DevExpress, Java, Embedded, Web, WordPress, ... Mobile (all main flavors), Web, Desktop, Client/Server Please visit Butterflyvista Professional Career Coaching with Sarah Weinberger Please visit Butterflyvista Desires Learn to play Beethoven Moonlight sonata on the piano! Universe, bring back Sarah Michelle Geller in Ringer

Updated on June 17, 2022

Comments

  • Sarah Weinberger
    Sarah Weinberger almost 2 years

    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.

    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

    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.

    Am I missing something? I am using SQL Server authentication.