-1
我一直在各地谷歌和這個網站試圖建議解決我目前得到的錯誤:用戶登錄失敗「dbAdmin」
「無法打開連接用戶登錄失敗‘dbAdmin’
Connection:Data Source =。\ SQLEXPRESS; Initial Catalog = stantecUsers; User Id = dbAdmin; Password = 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;
}
我不知道我需要從這裏去解決這個問題,它似乎不斷有這樣的幫助將是偉大的!
您是否能夠使用上述uid/pw從管理控制檯連接到數據庫? –
@KosalaW不,看起來我沒有...... – StealthRT
這意味着這個問題與C#無關。檢查是否可以在數據庫用戶列表中看到dbAdmin用戶。如果不是右鍵單擊並將dbAdmin添加到數據庫用戶列表中。如果可用,請檢查是否已將dbreader和dbwriter訪問dbAdmin。 –