我在與SQL Server ... 連接從這個代碼與Visual Studio的麻煩:Visual Studio的通信 - 服務器錯誤
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()
例外:
'System.Data.SqlClient.SqlException' in EntityFramework.dll
Additional information: Login failed for user 'sa'.
我試着進入設置來添加'sa'用戶作爲連接,但它不工作。 進一步瞭解詳細:
- 在C#
- 與Visual Studio的ASP.NET Framwork工作
- 寫作使用基本的SQL Server數據庫已經是建立在VS
我真的很感激任何可以給予的幫助,如果你願意進一步幫助我,請給我留言。謝謝!
我試圖使 '山' 的帳戶,我現在收到此錯誤:
'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.
連接字符串:
<configSections> <section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,
EntityFramework, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections> <connectionStrings> <add name="ContextClass"
connectionString="Data Source=(local);Persist Security
Info=True;database=db_FoodAllergy;User ID=sa;Password=saa"
providerName="System.Data.SqlClient" /> </connectionStrings>
如果我沒記錯的話sa會是數據庫的管理員 – codeMonger123