Sql server sql连接的网络相关错误
我试图首先使用实体框架代码创建一个简单的数据库,但当我运行我的项目时,我在从数据库检索列表的第行遇到异常: 例外情况: 运行时发生与网络相关或特定于实例的错误 正在建立与SQL Server的连接。找不到服务器,或者 无法访问。验证实例名称是否正确,以及 SQL Server配置为允许远程连接。(提供程序:SQL) 网络接口,错误:50-发生本地数据库运行时错误。 指定的LocalDB实例不存在 代码:Sql server sql连接的网络相关错误,sql-server,asp.net-mvc,entity-framework,ef-code-first,code-first,Sql Server,Asp.net Mvc,Entity Framework,Ef Code First,Code First,我试图首先使用实体框架代码创建一个简单的数据库,但当我运行我的项目时,我在从数据库检索列表的第行遇到异常: 例外情况: 运行时发生与网络相关或特定于实例的错误 正在建立与SQL Server的连接。找不到服务器,或者 无法访问。验证实例名称是否正确,以及 SQL Server配置为允许远程连接。(提供程序:SQL) 网络接口,错误:50-发生本地数据库运行时错误。 指定的LocalDB实例不存在 代码: public ActionResult Index() { using(va
public ActionResult Index()
{
using(var db=new OdeToFooddb())
{
var model = (from r in db.Restaurants select r).ToList();
return View(model);
}
}
public class Restaurant
{
public int Id { get; set; }
public string Name { get; set; }
public string City { get; set; }
public string Country { get; set; }
public ICollection<RestaurantReview> Reviews { get; set; }
}
型号:
public ActionResult Index()
{
using(var db=new OdeToFooddb())
{
var model = (from r in db.Restaurants select r).ToList();
return View(model);
}
}
public class Restaurant
{
public int Id { get; set; }
public string Name { get; set; }
public string City { get; set; }
public string Country { get; set; }
public ICollection<RestaurantReview> Reviews { get; set; }
}
公共级餐厅
{
公共int Id{get;set;}
公共字符串名称{get;set;}
公共字符串City{get;set;}
公共字符串国家{get;set;}
公共ICollection审阅{get;set;}
}
检查您的连接字符串。在@Sirwanafi中我应该检查什么?使用SQL Server Management Studio并尝试连接到您的服务器;这是由于框架和SQL Server之间的连接。测试SQL连接