用户登录失败' dbAdmin'

时间:2016-01-01 03:54:14

标签: c# sql sql-server web-services wcf

我一直在谷歌周围和这个网站尝试修复我目前得到的错误的建议:

  

"无法打开连接!用户' dbAdmin'。

登录失败      

连接:数据源=。\ SQLEXPRESS;初始目录= stantecUsers;用户ID = dbAdmin;密码= 123456789;"

我为 MS SQL 2012 EXPRESS 创建了一个登录名,以用户身份添加 dbAdmin enter image description here

我还确保数据库同时使用SQL Server和Windows身份验证模式: enter image description here enter image description here

对于我的WCF Web服务,我有以下连接字符串:

try
{
   string connetionString = @"Data Source=.\SQLEXPRESS;" + 
                             "Initial Catalog=stantecUsers;" +
                             "User Id=dbAdmin;" +
                             "Password=123456789;";
   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>() }
  };

  try
  {
      connection.Open();
      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() 
         });
       }

       read.Close();
       command.Dispose();
       connection.Close();

       return JsonConvert.SerializeObject(root, Formatting.Indented);
   }
   catch (Exception ex)
   {
       return "Can not open connection! " + ex.Message + "  Connection: " + connetionString;
   }
}
catch (SqlException e)
{
   return e.Message;
}

我不知道我需要从哪里开始才能解决这个问题似乎不断有这么大的帮助会很棒!

更新:尝试在数据库下添加用户时 enter image description here enter image description here enter image description here enter image description here enter image description here

1 个答案:

答案 0 :(得分:0)

奇怪的是,似乎我必须将&#34; db_owner&#34; 添加到用户的数据库安全设置中,并在拥有架构下添加正常工作...... enter image description here