2016-07-26 110 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服務)看到停止狀態或手動...右擊然後開始......然後問題就解決了。

相關問題