2015-11-27 79 views
0

我在與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.

+0

請嘗試打開指向該服務器的查詢選項卡,並使用您在sql server management studio中的代碼中的SA憑據來隔離您是否擁有正確的憑據。 – t1t1an0

+0

聽起來你的連接字符串有問題。這通常在app.config文件中設置。你能確認你的連接字符串中有正確的密碼嗎? – Tarzan

+0

我將憑據更改爲可以連接的其他數據庫用戶。我不再收到服務器錯誤...但我仍然收到相同的異常/錯誤...不知道該怎麼辦。有什麼建議麼? 異常:在EntityFramework.dll中發生類型爲「System.Data.SqlClient.SqlException」的異常,但未在用戶代碼中處理 其他信息:用戶'sa'的登錄失敗。 –

回答

0

我猜你不SQLSERVER的賬戶

下面這個啓用登錄啓用並記住設置sa的密碼

https://sudeeptaganguly.wordpress.com/2010/04/20/how-to-enable-sa-account-in-sql-server/

+0

不,這不起作用 - 現在我遇到了這個問題: 異常拋出:EntityFramework.dll中的'System.InvalidOperationException' 附加信息:此操作需要連接到'主'數據庫。無法創建與「主」數據庫的連接,因爲原始數據庫連接已打開且憑據已從連接字符串中刪除。提供未打開的連接。 –

+0

它似乎登錄,但無法連接到「主」架構, 您可能會發布您的連接字符串? – kcwu

+0

相關問題