EF无法在app.config中找到connectionstring [英] EF cant find the connectionstring in app.config

查看:173
本文介绍了EF无法在app.config中找到connectionstring的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个使用SQL Server数据库的WPF应用程序。当我从visual studio执行它时,它正确运行。问题是当我创建一个安装文件,安装它并运行它时(我使用InstallShield)。我得到一个例外:

System.InvalidOperationException:没有名为< 的连接字符串我在App.config中的连接字符串的名称> 可以在应用程序配置文件中找到。



这是我的连接字符串





< pre lang =HTML> < add 名称 = MimiNewestDBEntities < span class =code-attribute>

< span class =code-attribute> connectionString = metadata = res://*/DataBase.mdfConnection.csdl | res://*/DataBase.mdfConnecti on.ssdl | res://*/DataBase.mdfConnection.msl; provider = System.Data.SqlClient; provider connection string = data source = MIMI \ SQLEXPRESS;初始 目录 = MimiNewDB;集成 安全性 = True ; MultipleActiveResultSets = True; App = EntityFramework

providerName = System.Data.EntityClient / >





我尝试了什么:



我确实将App.config的属性Copy to output设置为Copy always,我仍然具有相同的异常

解决方案

确保配置文件是您的安装文件的一部分。


右键单击App。配置文件 - >选择属性 - >转到BuildAction - >在这里,您将在下拉列表中获得多个选项 - >选择嵌入式资源



嵌入式资源:将文件嵌入专用程序集清单资源中



对于交叉验证,请在发布应用程序后检查App.config或* .exe.config文件。


Hi,

I have a WPF app that uses SQL server database. It runs correctly when I execute it from visual studio. The problem is when I create an setup file, install it and run it (I use InstallShield). I get an exception:
System.InvalidOperationException: No connection string named <the name of my connection string which is in App.config> could be found in the application config file.

Here is my connection string


<add name="MimiNewestDBEntities" 

         connectionString="metadata=res://*/DataBase.mdfConnection.csdl|res://*/DataBase.mdfConnection.ssdl|res://*/DataBase.mdfConnection.msl;provider=System.Data.SqlClient;provider connection string="data source=MIMI\SQLEXPRESS;initial catalog=MimiNewDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework""

         providerName="System.Data.EntityClient" />



What I have tried:

I did set the App.config's property "Copy to output" to "Copy always", am still having the same exception

解决方案

Make sure the configuration file is part of your setup file.


Just right click on App.config file -> Choose Properties -> Go to BuildAction -> Here you will get multiple options in dropdown -> Choose "Embedded resource"

Embedded resource: Embeds the file in an exclusive assembly manifest resource

For cross verify, check App.config or *.exe.config file is present after publish the application.


这篇关于EF无法在app.config中找到connectionstring的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆