我正在尝试创建数据库架构的副本,然后在应用程序中临时使用它进行测试,这样我就不会更改实时数据。但是,无论我做什么,它总是给我这个错误:
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 中都这样做了,但我总是得到同样的错误。
最佳答案
Entity Framework 连接字符串通常看起来不像您显示的任何一个字符串。您的连接字符串看起来像一个普通的 sql server 连接字符串。
EF 连接字符串通常包含 EF 元数据。这是我的一个 EF 连接字符串中的示例:
所以你的连接字符串可能看起来有些不同,但它应该包含实体元数据引用等。
我会从生产中使用的实际连接字符串开始(如果你能得到它),甚至进行清理,然后相应地修改它。
关于c# - 为 EF 使用本地数据库副本 - "The specified named connection is either not found in the configuration",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36607117/