Click here to Skip to main content
15,912,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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


HTML
<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
Posted
Updated 8-Aug-18 2:44am
v2

Make sure the configuration file is part of your setup file.
 
Share this answer
 
Comments
berkumans 14-Mar-16 7:01am    
It is already in the project and always copied to the output, is there another way to put it in a setup file?
Mehdi Gholam 14-Mar-16 7:16am    
Check when you install the app, the correct config is beside it, if not then go to you install-shield configuration and check if the file is in there for the setup.
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.
 
Share this answer
 
Comments
berkumans 14-Mar-16 6:59am    
When I do this and run the application by Ctrl + F5 on VS I get the same exception even before creating the setup. Do you have an Idea on what it can be?
[no name] 14-Mar-16 8:28am    
Did you follow above process.

Make sure that connection string is present in your main application.
berkumans 14-Mar-16 10:50am    
Yeah, I followed it. Right clicked -> Properties -> Build action set to Embedded resource. When I run I get the exception. If I put it back to None works fine and throws the exception after setup creation.
berkumans 14-Mar-16 10:51am    
If I set it to Embedded resource or resource it produces the same effect. It only accepts None

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900