Vista trouble to write ConnectionString in App.config

Topics: Data Access Application Block
Dec 17, 2007 at 12:18 PM
My WinForm application allows user to change database connectionString at runtime.
Normally I'm able to write connectionString back to *.exe.config, except in Vista because of UAC.

Some one suggests me to move such configuration file to C:\Documents and settings\AllUsers\AppData

but in this case, Enterprise library (data access block) won't get correct connectionString??!

Does anybody can give me some helps? Thanks a lot.
I'm really confused about that.
Dec 17, 2007 at 12:36 PM
Hi,

It depends on what you mean by "moving the configuration file to the app data folder". By default EntLib reads the connection strings from the standard connectionStrings section in the app's configuration file, so if you want the connection strings in a different location you'll have to do it in a way that is compatible with this usage; relying on the "configSource" feature (see http://msdn2.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource.aspx) is the only way I can think of for accomplishing this.

An alternative is to rely on user level settings (see http://msdn2.microsoft.com/en-us/library/a65txexh(VS.80).aspx) and create Database instances supplying the actual connection string retrieved from these user settings instead of going through the factories. Keep in mind though that these settings will not be shared among users, some features like instrumentation will not work and you will need to implement a way to determine what kind of Database class to create (but this will not be an issue if you only want to support a fixed DBMS).

Hope this helps,
Fernando
Dec 17, 2007 at 1:09 PM
Thank you so much for your help.

1. The "configSource" feature doesn't support relative path which is in different location. That is, if I set

<connectionStrings configSource="D:\connectionStrings.Config" />

it doesn't work.

But it works for

<connectionStrings configSource="connectionStrings.Config" />

2. It doesn't solve my problem.


Do you have more ideas to solve this problem? Thanks.



fsimonazzi wrote:
Hi,

It depends on what you mean by "moving the configuration file to the app data folder". By default EntLib reads the connection strings from the standard connectionStrings section in the app's configuration file, so if you want the connection strings in a different location you'll have to do it in a way that is compatible with this usage; relying on the "configSource" feature (see http://msdn2.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource.aspx) is the only way I can think of for accomplishing this.

An alternative is to rely on user level settings (see http://msdn2.microsoft.com/en-us/library/a65txexh(VS.80).aspx) and create Database instances supplying the actual connection string retrieved from these user settings instead of going through the factories. Keep in mind though that these settings will not be shared among users, some features like instrumentation will not work and you will need to implement a way to determine what kind of Database class to create (but this will not be an issue if you only want to support a fixed DBMS).

Hope this helps,
Fernando

Dec 17, 2007 at 9:15 PM
Comments inline,


1. The "configSource" feature doesn't support relative path which is in different location. That is, if I set


Junctions may be help you here, but I agree it's probably pushing it.


2. It doesn't solve my problem.


What aspects of this solution are less desirable? Not going through the factories or saving to the user's profile?
Dec 18, 2007 at 1:26 AM

1. I hope this bug will be fixed soon by EnterLibrary. I really need a relative physical path.

2. The reason is that we don't want to take windows user authentication. One windows user can log into my program with different user name, which is stored in remote database USERS table. Another point is one windows user may want to save several ConnectionStrings. So I think this solution is less desirable.

Thank you again for you help!



fsimonazzi wrote:
Comments inline,


1. The "configSource" feature doesn't support relative path which is in different location. That is, if I set


Junctions may be help you here, but I agree it's probably pushing it.


2. It doesn't solve my problem.


What aspects of this solution are less desirable? Not going through the factories or saving to the user's profile?

Dec 18, 2007 at 6:03 AM

I found a way to accomplish this.

First, I used the way of "Using a different ConfigurationSource" with the help of Tom Hollander's blog
(http://blogs.msdn.com/tomholl/archive/2006/04/02/entlib2externalconfig.aspx),

then I used ExeConfigurationFileMap to read configurations for my own codes.




fsimonazzi wrote:
Comments inline,


1. The "configSource" feature doesn't support relative path which is in different location. That is, if I set


Junctions may be help you here, but I agree it's probably pushing it.


2. It doesn't solve my problem.


What aspects of this solution are less desirable? Not going through the factories or saving to the user's profile?