S
SoxFan44
Guest
I have a solution that has 2 web services and 2 windows services. All projects have their own web.config or app.config, but they all have the same database connection string. I would like to pull that out into a config manager class. In the configmanager class I open an app.config file like this:
ConfigurationFileMap map = new ConfigurationFileMap(@"C:\temp\app.config");
var config = ConfigurationManager.OpenMappedMachineConfiguration(map);
When I try to access the connection string by name, I get a null reference exception. I found out that whats happening is that its the service is still trying to get its connection strings from its own app.config and I cant figure out what.
Any ideas how I can accomplish what Im trying to do? Thanks.
Here is my app.config for configmanager:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="string1" connectionString="mystring" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
Continue reading...
ConfigurationFileMap map = new ConfigurationFileMap(@"C:\temp\app.config");
var config = ConfigurationManager.OpenMappedMachineConfiguration(map);
When I try to access the connection string by name, I get a null reference exception. I found out that whats happening is that its the service is still trying to get its connection strings from its own app.config and I cant figure out what.
Any ideas how I can accomplish what Im trying to do? Thanks.
Here is my app.config for configmanager:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="string1" connectionString="mystring" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
Continue reading...