2016-04-13 32 views
3

我試圖創建數據庫模式的副本,然後在應用程序中暫時用它來進行測試,所以我不用不會改變實時數據。但是,無論我做什麼,它總是給我這個錯誤:對EF使用本地數據庫副本 - 「在配置中找不到指定的命名連接」

An exception of type 'System.ArgumentException' occurred in System.Data.Entity.dll but was not handled in user code 

Additional information: The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid. 

我試圖讓我的連接字符串如下所示:

<add name="EntitiesConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\vipertest.mdf;Integrated Security=True" providerName="System.Data.SqlClient" /> 

<add name="EntitiesConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\vipertest.mdf;Integrated Security=SSPI;User Instance=True" providerName="System.Data.SqlClient"/> 

我曾與一個MDF文件試過,沒有。

我在Web.Config和app.config中都這樣做了,但我總是得到相同的錯誤。

+0

您的連接字符串實際上看起來不像實體框架連接字符串。發佈可能有助於解釋的答案。 –

回答

2

實體框架連接字符串通常看起來不像您要顯示的任一字符串。您的連接字符串看起來像一個純sql服務器連接字符串。

EF連接字符串通常包含EF元數據。這是從我的EF的連接字符串的一個例子:

所以你的連接字符串可能看起來有些不同,但它應該包含實體引用的元數據等

我會先從生產中使用的實際連接字符串(如果可以的話),甚至可以消毒,然後相應地修改它。

This MSDN article on EF connection strings可能會有所幫助。

+0

謝謝你的迴應,我沒有想到 - 我會去試試:) –

+0

它的工作!我已將答覆標記爲答案 - 謝謝! 我所做的就是將生產中的元數據連接字符串與您所說的一樣,然後用第一個連接字符串替換連接字符串部分,這個連接字符串是我在問題中的一個示例。 –

+0

很高興幫助你。 –

相關問題