I am using VS 2008.
I have a service that needs to be deployed. The service will not be used from a .NET client (such as a website or a Windows client). This requires a database connection.
First, I had a console application that called the service, and the connection string was set in the app.config of the console application. I want to move the connection string to the service. Therefore, in the web.config file that comes with the service, I add the following:
<connectionStrings> <clear /> <add name="REConnectionString" connectionString="Data Source=MyServer;Initial Catalog=MyDatabase;Integrated Security=True;" providerName="System.Data.SqlClient" /> </connectionStrings>
And in my MyService.svc.cs I have the following:
private readonly string connectionString = ConfigurationManager.ConnectionStrings["REConnectionString"].ConnectionString;
But when I start the service, this connectionString is null. How to get this value from web.config?
I even added the following, but it also does not work:
<appSettings> <add key="REConnectionString" value="Data Source=MyServer;Initial Catalog=MyDatabase;Integrated Security=True;"/> </appSettings>
If I scroll through the list of connection strings, it continues to return the connection string from the calling application. Is it not possible to use the configuration file?
source share