2016-07-26 77 views
0

我有一个单独的DLL,处理到数据库的连接,从而拥有模型和api上下文。在app.config'的行为就像在web.config并保持连接的详细信息。然而我不断收到以下错误与实体框架的DLL无法连接到数据库

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: 26 - Error Locating Server/Instance Specified)

所以我从另一种更传统的MVC web.config文件复制连接字符串,并仍然出现错误。

奇怪的是,以下工作:

update-database -verbose 

app.config具有下面的连接字符串:

<add name="DefaultConnection" 
    connectionString="data source=(LocalDb)\v11.0;initial catalog=APIEntities-01;persist security info=True; Integrated Security=SSPI;MultipleActiveResultSets=True" 
    providerName="System.Data.SqlClient" /> 

dbContext指向它

public ApiContext() : base("DefaultConnection") 
{ 
} 

正如我说的,这在传统的MVC中工作210,但使用引用实体框架和类似的似乎无法找到数据库的DLL。有什么建议么?

EF 6

回答

1

我假定连接字符串,因为 “数据源=(的LocalDB)\ V11.0;初始目录= APIEntities-01” 是本地到PC的路径。您必须提供您需要使用的真正的SQL Server。看到这一点:

Change default location of LocalDb

0

有些时候,它的hapen当SQL Server未能打开。然后打开SQL服务器配置,然后选择(SQL SERVER服务)看到停止状态或手动...右击然后开始......然后问题就解决了。

相关问题