Custom Configuration File

Topics: Data Access Application Block
Jan 22, 2010 at 12:14 PM


I would like to use DAAB 3.1 with a custom configuration file and not with the application's config file.

Can anyone point me to the right direction?

Thank you.

Jan 22, 2010 at 1:25 PM

You do not state what you want to achieve by having a separate custom config file, but there are a couple of different things you can do.

If you want to "modularize" you configuration, you can break out certain config sections to separate files, using the configSource attribute:

// point out a file containing the connectionStrings config section
<connectionStrings configSource="connections.config"></connectionStrings>

You can also open a specific configuration file by callingConfigurationManager.OpenExeConfiguration

Jan 22, 2010 at 2:53 PM
Edited Jan 22, 2010 at 3:12 PM

I will try to describe the whole situation then.

I am creating an application that has the ability to connect to many databases. So i need somewhere to keep the list of connections strings. So far it is application.config

Now this connection strings are not static, meaning that users must be able to create new connection strings, or delete through an interface i have created in the application. So far everything worked fine until the first click once update. When that happened users lost their connection strings that they had created.

So at this point the idea came into my mind to save the connection strings into an external file and instruct Data Access Application Block to look at that file for the connection strings. So when i do a new click once update the connection strings will not be lost.

So according to your suggestion the first option with the configSource attribute sounds great. But at a new click once update am i going to loose again the connection strings or click once will "see" this file and bring it to the new application folder installation?

This is the whole story. I thought just finding a way to save connection strings in an external file would be enough but now you know what i want to accomplish and what the problem is.


Jan 25, 2010 at 3:34 AM

I'm not really familiar with click once but another method you can try is by using an instance of IConfigurationSource, specifically the FileConfigurationSource.  For the sample code -,  It will work as long as the file path you specify is correct.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.

Jan 25, 2010 at 11:33 AM

Hi Sarah and thank you for your answear.

I have read the article. The solution is similar with what bfallar3 pointed to me but it is implemented differently. The interesting part was the example with the last config file data-filesource.config but the author is not making clear if we need to put a reference for this file in app/web.config file. So it will take me some time to figure out this details and see if it is the solution i was looking for.

I will implement both and try them one at a time.

Thank you for your time.

Jan 26, 2010 at 12:50 AM

No, you need not have a reference for that file in the config file.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.