locked
login failed for user 'sa' RRS feed

  • Question

  • I am using c#.net 2008. when i run application, the following error is appeared like this.....

    System.data.sqlclient.sqlexception: cannot open database "dbname" requested by the login. the login failed. login failed for user 'sa'.



    Nithiyanantham

    Tuesday, October 6, 2015 7:38 AM

Answers

  • A SA user might also not have been created when the server was installed; but that might be unlikely if somebody provided you with username and password.

    Note that using SA as a user to connect to databases is a very bad habit; that should only be necessary if have to do database maintenance work from your application.

    • Proposed as answer by Kristin Xie Monday, October 12, 2015 8:40 AM
    • Marked as answer by Kristin Xie Wednesday, October 14, 2015 9:59 AM
    Tuesday, October 6, 2015 3:19 PM

All replies

  • You need to double check your connection string in your app.config file or else. It seems you've set the "dbname" as the actual DataBase name. Please see below an example of SQL connection string how it should look like:

    Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
    Password=myPassword;

    https://www.connectionstrings.com/sql-server-2012/


    Fouad Roumieh


    Tuesday, October 6, 2015 7:59 AM
  • This sounds like a pretty clear case of the SQL server denying the connection.

    Most likely cases are:
    You got the wrong username/passwort combination
    The SQL server instance is set to not accept connections via the network (or at least no login tries for this user that do not come from Localhost). A common security approach for servers.

    Is the DB running on the same computer or a different one? When was it installed? Who is the admin of the DB?

    Tuesday, October 6, 2015 8:29 AM
  • Instead of us guessing, could you put the part of the code that connects to the DB here?

     

    Noam B.


    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...

    Tuesday, October 6, 2015 11:05 AM
  • A SA user might also not have been created when the server was installed; but that might be unlikely if somebody provided you with username and password.

    Note that using SA as a user to connect to databases is a very bad habit; that should only be necessary if have to do database maintenance work from your application.

    • Proposed as answer by Kristin Xie Monday, October 12, 2015 8:40 AM
    • Marked as answer by Kristin Xie Wednesday, October 14, 2015 9:59 AM
    Tuesday, October 6, 2015 3:19 PM