I have a C# 2010 desktop application that will be calling a dll. The dll is code that is to be shared between different application. I want to be able to pass database connection values to the app.config file in the dll.
Thus can you show me and/or explain to me how to accomplish this goal?
Loading
VulpesPosted Jun 23, 2013, 7:18 PM
2. The dll can only have one app.config file. However, the file can contain multiple connection string settings each distinguished by its name. So each client of the dll can call the AddConnectionString method with its own settings. It would clearly be sensible to base the name of those settings on the name of the program calling the dll to ensure there are no clashes.
3. I don't understand this question. I didn't know the dll was calling another program and, even if it is, I don't see how it can have 4 app.config files unless you're using custom configuration files in addition to the default one?
VulpesPosted Jun 24, 2013, 11:26 AM
scampercatPosted Jun 23, 2013, 10:53 PM
The program that is called in the dll has a solution file with 4 project files. Each project file has a app.config file. Thus there was a total of 4 app.config files.
Thus can a dll be setup to access a solution file that has 4 app.config files? If so, how can I access the specific app.config I need when accessing the solution file that has 4 app.config files? There is only one specific app.config file that I will probably need to access.
Can you show me code on how to access the specific app.config file in a specific project file?
dcPosted Jun 23, 2013, 4:53 PM
1. you stated "You'll need to add a reference to System.Configuration.dll to your dll if you don't have one already." Will I need to add this reference in the program that calls the dll?
2. you stated, "You can then call this method from the client with code such as the following:
SomeClass.AddConnectionString (name, connectionString, providerName);" When I need to do this for each app.config file?
3. There are 4 app.config files in the program called by the dll. Thus can you tell me how to use the code you suggested for 4 app.config files?
VulpesPosted Jun 23, 2013, 11:38 AM
A client of the dll can then call the method and pass the appropriate database connection values.
The code for the method will be something on these lines:
// ....
You'll need to add a reference to System.Configuration.dll to your dll if you don't have one already.
You can then call this method from the client with code such as the following:
SomeClass.AddConnectionString (name, connectionString, providerName);