2015-11-30 58 views
0

我在与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> 
+0

如果我没记错的话sa会是数据库的管理员 – codeMonger123

回答

0

您没有提供登录凭据在本地sql服务器上。所以试着使用这个连接字符串。它会为你工作..

Data Source=(local);database=db_FoodAllergy;Integrated Security=true; providerName="System.Data.SqlClient