Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2003
    Provided Answers: 1

    Question Unanswered: Login failed for user 'dbAdmin' (even though i just created it and restarted SQL)

    I've been all around google and this site trying suggestions to fix the error I am currently getting:

      "Can not open connection! Login failed for user 'dbAdmin'.
    Connection: Data Source=.\\SQLEXPRESS;Initial Catalog=stantecUsers;User Id=dbAdmin;Password=123456789;"

    I created a login for my **MS SQL 2012 EXPRESS** adding **dbAdmin** as the user:
    Click image for larger version. 

Name:	wEpGZ.png 
Views:	5 
Size:	71.3 KB 
ID:	16694

    And I also made sure the database was using both SQL server and Windows Auth Mode:
    Click image for larger version. 

Name:	kG6IV.png 
Views:	4 
Size:	79.4 KB 
ID:	16697
    Click image for larger version. 

Name:	xh3cP.png 
Views:	4 
Size:	76.3 KB 
ID:	16693

    And for my WCF web service I have the following connection string:
           string connetionString = @"Data Source=.\SQLEXPRESS;" + 
                                     "Initial Catalog=stantecUsers;" +
                                     "User Id=dbAdmin;" +
           string sql = "SELECT * " +
                        "FROM [stantecUsers].[dbo].[users] AS stantecUsers " +
                        "INNER JOIN [stantecUsers].[dbo].[usersData] AS stantecUserData " +
                        "ON stantecUsers.link2Data = stantecUserData.link2Data " +
                        "WHERE stantecUsers.phoneNum = '" + phoneNum + "' " +
                        "ORDER BY stantecUsers.ID ASC;";
           SqlConnection connection;
           SqlCommand command;
           connection = new SqlConnection(connetionString);
           // Create a new object that matches the structure of the JSON file.
          var root = new RootObject
              DATA = new DATA { clocked = new List<Clocked>() }
              command = new SqlCommand(sql, connection);
              SqlDataReader read = command.ExecuteReader();
              while (read.Read())
                 root.DATA.firstName = read["firstName"].ToString();
                 root.DATA.lastName = read["lastName"].ToString();
                 root.DATA.phoneNum = read["phoneNum"].ToString();
                 root.DATA.title = read["title"].ToString();
                 root.DATA.emailAddress = read["emailAddress"].ToString();
                 root.DATA.image = read["image"].ToString();
                 root.DATA.clocked.Add(new Clocked { 
                      date = read["theDate"].ToString(), 
                      type = read["theType"].ToString() 
               return JsonConvert.SerializeObject(root, Formatting.Indented);
           catch (Exception ex)
               return "Can not open connection! " + ex.Message + "  Connection: " + connetionString;
        catch (SqlException e)
           return e.Message;
    I'm not sure where I need to go from here in order to fix the issue it seems to continuously have so help would be great!

    when trying to add user under database:
    Click image for larger version. 

Name:	jK7fY.png 
Views:	2 
Size:	82.3 KB 
ID:	16696
    Click image for larger version. 

Name:	RviFc.png 
Views:	2 
Size:	71.3 KB 
ID:	16692
    Click image for larger version. 

Name:	9SZ0s.png 
Views:	3 
Size:	78.6 KB 
ID:	16695
    Click image for larger version. 

Name:	xIvNJ.png 
Views:	3 
Size:	91.9 KB 
ID:	16698
    Last edited by StealthRT; 01-01-16 at 13:43.

  2. #2
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    I'll assume that you created the database User first, then tried to create the SQL Server login. If that was the case, then there is a very high probability that:
       @LoginName sysname = N'dbAdmin'
    ,  @Password  sysname = N'123456789'
    ,  @UserName  sysname = N'dbAdmin'
    EXECUTE sp_change_users_login 'Update_One'
    ,  @UserName, @LoginName, @Password
    ...will fix your problem.

    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Jan 2016
    Provided Answers: 1

    run this

    to resolve this error sync the sid between the user of the restored database and the login of the test server.
    To do this execute
    EXEC sp_change_users_login 'AUTO_FIX', 'database username'

  4. #4
    Join Date
    Jan 2003
    Provided Answers: 17
    You can also get a better detailed message for login failures from the SQL Server errorlog. Check for these under Management->SQL Server Logs->Current - (some date)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts