I have a Helper project H, with a config file that is to be used as a shared configSource file from other projects.
The code in file (SharedConnectionString.config):
<?xml version="1.0" encoding="utf-8"?>
<connectionStrings>
<add name="myConn" connectionString="Data Source=MyServer;Initial Catalog=MyDb;Persist Security Info=True;User ID=Username; password=PW;" providerName="System.Data.SqlClient" />
</connectionStrings>
I have a test project A that have it's own App.config and the SharedConnectionString.config added as file link
Config files in project A:
On the App.config I have:
<connectionStrings configSource="SharedConnectionStrings.config" />
Now, the test project compiles, the unit tests run successfully but the Live Unit Test feature from Visual Studio presents an error:
I tried the solution in here and here. None of there fixed the problem.
Opened an issue with Microsoft to see if help comes from somewhere..
Related
Currently I'm creating a new Solution with 1 Class Library Project. I installed EntityFramework 6.4.4 and add App.config that only contains 1 Connection String. When I run following command:
Enable-Migrations -ConnectionStringName AppDbContext
App.Config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="AppDbContext" providerName="System.Data.SqlClient" connectionString="Data Source=(local);Initial Catalog=MY_DATABASE;Integrated Security=SSPI;MultipleActiveResultSets=True"/>
</connectionStrings>
</configuration>
I got result:
No Connection String Could Be Found In The Application Config File
What could have gone wrong?
Thanks a lot.
I have two projects in a solution in Visual Studio 2010, Project1 and Project2.
Project1 is the parent project and has a config file called ConnectionStrings.config that contains connection strings used by both projects.
I have added the ConnectionStrings.config file from Project1 into Project2 as a linked file.
When I publish this to our webserver it works fine, Project2 can read data in from our database using the connection strings from the config file in Project1.
When I'm working on local and debug Project2 I get the following error which I assume means that it can't see the linked file:
Unable to open configSource file 'ConnectionStrings.config'.
(C:\Project2\web.config line 10)
Project1 ConnectionStrings.config
<?xml version="1.0"?>
<connectionStrings>
<add name="myConnectionString" connectionString="Data Source=***;Initial Catalog=***;Integrated Security=False; Password=***;User ID=***"
providerName="System.Data.SqlClient" />
</connectionStrings>
Project2 web.config
<?xml version="1.0"?>
<configuration>
<connectionStrings configSource="ConnectionStrings.config"/>
</configuration>
How can I get Project2 to read this config file from Project1?
Thanks
NO, I don't think you can do that. If you really want the same connection string to be shared across multiple project then consider having that connection string specified in machine.config rather.
Used console application and I have a problem on the app.config file. By right, the code should be correct according to the various sources found in the Internet but my coding is not working for no reason. Anyone can advise me on this?
And the <configuration> appears to be underlined with wriggly blue line, is it a warning or something? I dont know why it appears like this.
[EDITED]
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSetting></configSetting>
<connectionStrings>
<add name="Production"
providerName="System.Data.SqlClient"
connectionString="Data Source=EBSDLAB1SERVER2;Initial Catalog=Production;Integrated Security=True"/>
</connectionStrings>
</configuration>
The error shows, Unhandled Exception: System.Configuration.ConfigurationErrorException:Configuration system fail to initialize ---
System.Configuration.ConfigurationErrorException: Unrecognized configuration section connectionstring
Configuration system failed to initialize
In your App.Config file you need a section for connection strings, it should look like:
<connectionStrings>
<clear />
<add name="Production"
providerName="System.Data.ProviderName"
connectionString="ConnectionStringGoesHere" />
</connectionStrings>
There's more information regarding this here.
I managed to solve this problem which is to copy the app.config file to the same folder as the console application.exe and rename the app.config file according to the console application.exe!
Thank you all for the help!
My Program uses EF to access data from a SQL CE database. When debug the application using debug setup it works fine but if I use release setup I get a MetadataException when the program tries to access the database through EF.
What I've checked so far:
Debug and release configuration is identical (same target platform)
The app.config is copied to the same directory as the executable (\Release)
The sdf database file is copied to \Release\
Metadata Artifact Processing is set to Embed in Output Assembly
Connection string name is identical in app.config and EF model
My app.config:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="GeoDataEntities" connectionString="metadata=res://*/Model.EF.Model.csdl|res://*/Model.EF.Model.ssdl|res://*/Model.EF.Model.msl;provider=System.Data.SqlServerCe.3.5;provider connection string="Data Source=|DataDirectory|\GeoData.sdf"" providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
The assembly Model.EF is the namespace and Model the name of the edmx, I think that should be right.
I know that there a lot of posts and blogs about MetadataException and I've tried to solve this but nothing have worked so far.
Best regards
Jay
I really don't know what I've done but it's working since I've checked in and checked out from TFS.
I have an app.config file inside my TestProject, but when I try to read it using ConfigurationManager it reads from somewhere else and it's none of my app.config's. How to correct this?
Current config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="Production" connectionString="Server=127.0.0.1,2345;Uid=user;Pwd=password;Initial Catalog=DATABASE_DATA"/>
</connectionStrings>
</configuration>
Current code:
ConfigurationManager.ConnectionStrings[0].ConnectionString
Expected output:
"Server=127.0.0.1,2345;Uid=user;Pwd=password;Initial Catalog=DATABASE_DATA"
Actual output:
"data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
Try Referencing it by name.
ConfigurationManager.ConnectionStrings["Production"].ConnectionString
The config files automatically integrate machine.config which has that SQLEXPRESS connection string by default.