我一直在谷歌周围和这个网站尝试修复我目前得到的错误的建议:
"无法打开连接!用户' dbAdmin'。
登录失败连接:数据源=。\ SQLEXPRESS;初始目录= stantecUsers;用户ID = dbAdmin;密码= 123456789;"
我为 MS SQL 2012 EXPRESS 创建了一个登录名,以用户身份添加 dbAdmin :
我还确保数据库同时使用SQL Server和Windows身份验证模式:
对于我的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;
}
我不知道我需要从哪里开始才能解决这个问题似乎不断有这么大的帮助会很棒!