我在與Visual Studio與SQL Server連接的麻煩通信...SQL Server和Visual Studio的
從這個代碼:
#region User management
public ActionResult SearchByRestaurant()
{
User objUser = new User();
if (Session["UserId"] != null)
{
int id = Convert.ToInt32(Session["UserId"]);
objUser = objContext.ContextUser.Find(id);
}
objUser.SearchResult = new List<SearchResult>();
objUser.PreferencesList = objContext.ContextPreferences.Where(s => s.Status == 1).ToList()
objUser.RestaurantListAll = objContext.ContextRestaurant.Where(s => s.Status == 1).ToList();
if (objUser.SelectedPreferences == null)
objUser.SelectedPreferences = new int[] { };
return View(objUser);
}
我得到一個異常這一行:
objUser.PreferencesList = objContext.ContextPreferences.Where(s => s.Status == 1).ToList()
例外:
Exception thrown: 'System.Data.SqlClient.SqlException' in EntityFramework.dll
Additional information: Login failed for user 'sa'.
我試着進入設置來添加'sa'用戶作爲連接,但它不工作。
更多詳情:
Working with Visual Studio ASP .Net Framwork
Writing in C#
Using a basic SQL database that is already setup in VS
我真的很感激,可給予任何幫助,如果你有足夠的願意幫我請留言給我。謝謝!
更新:
我試圖使「山」的帳戶,我現在收到此錯誤:
Exception thrown: 'System.InvalidOperationException' in EntityFramework.dll
Additional information: This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection.
請嘗試打開指向該服務器的查詢選項卡,並使用您在sql server management studio中的代碼中的SA憑據來隔離您是否擁有正確的憑據。 – t1t1an0
聽起來你的連接字符串有問題。這通常在app.config文件中設置。你能確認你的連接字符串中有正確的密碼嗎? – Tarzan
我將憑據更改爲可以連接的其他數據庫用戶。我不再收到服務器錯誤...但我仍然收到相同的異常/錯誤...不知道該怎麼辦。有什麼建議麼? 異常:在EntityFramework.dll中發生類型爲「System.Data.SqlClient.SqlException」的異常,但未在用戶代碼中處理 其他信息:用戶'sa'的登錄失敗。 –