LocalSqlServer and OraAspNetConString Won't Die!

Topics: Data Access Application Block
Jun 6, 2012 at 9:02 PM

I keep deleting these from the config (because I have code to allow user to select database by enumerating these connections) and Entprise Configuration tool keeps adding them back in!

What gives?  Why won't they die?  They're just connection strings, right?  Why would they keep getting added back?

Thanks

Ray

Jun 7, 2012 at 12:06 AM

The Data Access Application Block internally is coupled to the connectionStrings configuration section so it is finding all connectionStrings in the configuration.  LocalSqlServer and OraAspNetConString have probably been added to machine.config.  If they are removed from machine.config then the configuration tool won't pick them up any more.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Jun 7, 2012 at 2:38 PM
Edited Jun 7, 2012 at 2:39 PM

Removing the LocalSqlServer from machine.config fixed this, thank you.  This raises an important question for me though.  Why would the enterprise library configuration for my single application INSIST that this needed to be there?  Surely my application configuration should be able to only contains the connections I want to use?

Also, now this is gone from the application config file, when I deploy this application which enterprise library still pick up other settings from the machine config file when I cycle though this list to populate my combo box?

Thanks

Ray

Jun 7, 2012 at 4:30 PM

At runtime, the contents of app.config are merged with machine.config so your app.config is not isolated from machine.config.  For configuration, the dataConfiguration section is linked to the connectingSettings so when the configuration tool runs the machine.config settings are also picked up.  

On the production server you shouldn't have to make any changes.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Jun 7, 2012 at 4:36 PM

Thanks for the reply.  It seems like these connections also exist on the deployed machine.  Is there some way to have them NOT merge with the machine config, or to isolate them or flag them in some way so we can still enumerate through our connections to populate a combo box?

Thanks again

Ray

Jun 7, 2012 at 5:59 PM

If this is just for display and doesn't involve the configuration tool then this doesn't have much to do with Enterprise Library.  :)

If you just need to populate a combo box then you could get all of the machine.config connections and then exclude them from your list:

    var machineConfigConnections = 
            ConfigurationManager
                .OpenMachineConfiguration()
                .GetSection("connectionStrings") 
            as System.Configuration.ConnectionStringsSection;

    var machineConfigConnStrings = 
            machineConfigConnections.ConnectionStrings.Cast<ConnectionStringSettings>();
            
    var allConnStrings = 
            ConfigurationManager.ConnectionStrings.Cast<ConnectionStringSettings>();

    var connectionStringsToDisplay = allConnStrings.Except(machineConfigConnStrings);

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

 

 

Jun 7, 2012 at 8:39 PM

That worked like a charm, thank you SO much for your advice. :)

Ray