db模式的实体框架无法连接到服务器

时间:2017-01-23 10:46:41

标签: entity-framework entity db-first

我首先尝试使用db连接到db实例,我创建了一个连接

 <add name="Entities" 
      connectionString="metadata=res://*/Models.ModelCmarket.csdl|res://*/Models.ModelCmarket.ssdl|res://*/Models.ModelCmarket.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(localdb)\v12.0;initial catalog=Cevaheer;integrated security=True;trustservercertificate=False;multisubnetfailover=True;MultipleActiveResultSets=True;multipleactiveresultsets=True;App=EntityFramework&quot;" 
      providerName="System.Data.EntityClient" />

我总是收到错误 -

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. The specified LocalDB instance does not exist.)

但如果我尝试

<add name="CevhermarketEntities" 
     connectionString="Data source=(localdb)\v12.0;initial catalog=Cevaheer;integrated security=True;trustservercertificate=False;multisubnetfailover=True;MultipleActiveResultSets=True;user id=dbuser;password=flexsin@123!;multipleactiveresultsets=True;"
     providerName="System.Data.SqlClient" /> 

我可以连接,也可以从VS sql server explorer和SSMS连接。

1 个答案:

答案 0 :(得分:1)

首先 - 在开始之前,有4个问题可能导致 常见 LocalDb SqlExpress Sql Server连接错误 SQL Network Interfaces, error: 50 - Local Database Runtime error occurred { {3}}

我发现最简单的方法是执行以下操作 - 我附上了图片和步骤以寻求帮助。

首先验证您已安装的实例,您可以通过检查注册表 运行cmd

来执行此操作
  1. cmd> Sqllocaldb.exe i
  2. cmd> Sqllocaldb.exe s "whicheverVersionYouWantFromListBefore" 如果此步骤失败,您可以使用选项d cmd> Sqllocaldb.exe d "someDb"
  3. 删除
  4. cmd> Sqllocaldb.exe c "createSomeNewDbIfyouWantDb"创建 - 图片错误
  5. cmd> Sqllocaldb.exe start "createSomeNewDbIfyouWantDb"
  6. rename the V11 or 12 to mssqllocaldb