locked
Login failed for user 'sa' RRS feed

  • Question

  • I am trying to access a sql databse using c# by the following program
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.SqlClient;
    
    namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
                SqlConnection myConnection = new SqlConnection("user id=sa;" +
                                           "password=password;server=localhost;" +
                                           "Trusted_Connection=no;" +
                                           "database=date; " +
                                           "connection timeout=30");
                try
                {
                    myConnection.Open();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                    System.Threading.Thread.Sleep(100000);
                }
            }
        }
    }
    
    but I get an error:
     Login failed for user 'sa'
    the failed login is not listed in the error log file(although auditing is configured and logging in from managment studio is listed)
    I can access the databse using sql managment studio with that login(sa).
    thanks
    rotem blumberg
    Friday, January 8, 2010 7:11 PM

Answers

  • Do you see an 18456 login failed error ?? It should be included in the error log file or the windows event viewer .

    The error 18456 has several states in them , based on the state of this error it is easy to trouble shoot the
    login failure.I have an article here http://sql-articles.com/articles/troubleshooting/troubleshooting-login-failed-error-18456 which explains almost of the states with its cause and ways to overcome that .
    Please have a look at this article and you should be able to get to state from SQL error log file .

    Run the trace in the SQL server and see whether the connection is actually coming in to the SQL server , if it is not getting recorded in the errorlog then i am afraid that your connection is not reaching the DB engine.

    Do let us know if you have more queries.


    Thanks, Leks
    Friday, January 8, 2010 10:53 PM
  • Can you provide the server name or computer name instead of localhost? In this case C# is not able to connect SQL server itself that's why no entry is found in errorlog. You can also remove the trusted parameter in the connecction string since you have already specified username and password. For more info on connection string check the link below

    http://www.connectionstrings.com/sql-server-2005
    Vidhya Sagar. Mark as Answer if it helps!
    Saturday, January 9, 2010 2:21 AM

All replies

  • Do you see an 18456 login failed error ?? It should be included in the error log file or the windows event viewer .

    The error 18456 has several states in them , based on the state of this error it is easy to trouble shoot the
    login failure.I have an article here http://sql-articles.com/articles/troubleshooting/troubleshooting-login-failed-error-18456 which explains almost of the states with its cause and ways to overcome that .
    Please have a look at this article and you should be able to get to state from SQL error log file .

    Run the trace in the SQL server and see whether the connection is actually coming in to the SQL server , if it is not getting recorded in the errorlog then i am afraid that your connection is not reaching the DB engine.

    Do let us know if you have more queries.


    Thanks, Leks
    Friday, January 8, 2010 10:53 PM
  • Can you provide the server name or computer name instead of localhost? In this case C# is not able to connect SQL server itself that's why no entry is found in errorlog. You can also remove the trusted parameter in the connecction string since you have already specified username and password. For more info on connection string check the link below

    http://www.connectionstrings.com/sql-server-2005
    Vidhya Sagar. Mark as Answer if it helps!
    Saturday, January 9, 2010 2:21 AM