Remove default Database Settings in Enterprise Library Configuration V5

Topics: Data Access Application Block
Oct 19, 2011 at 5:52 AM

Hi,

I'm quite new to the Enterprise Library. I have created a empty C# 4 console project  and added the app.config file. By right-clicking and opening the Enterprise library configuration window I managed to add a logger to my application and all is fine. The problem I have is that every time I open the Configuration window a Database Settings is there and causes a validation error. If I remove the database setting and save and reopen the Configuration window the Database Setting is there again and causes a validation error.

Its impossible for me to remove the Database Setting. How do I do this?

Oct 20, 2011 at 5:47 AM
Edited Oct 20, 2011 at 6:33 AM

The validation message you are seeing is actually a warning so it does not interfere with editing and saving the configuration file.  You can safely ignore that warning message.

It if is a nuisance then you could set a value for the Default Database and save the configuration.  This will save a dataConfiguration section in your config file.  

 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>  
        <section name="dataConfiguration" 
type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
requirePermission="true" />
</configSections>
<dataConfiguration defaultDatabase="LocalSqlServer" />
</configuration>

 

It shouldn't do any harm but it does seem a bit excessive (and potentially confusing) to save actual configuration to simply eliminate a warning message from the configuration tool.

If you are really keen to remove the section it is possible.  The reason the Database Settings is showing up is because there is probably an entry in machine.config for connectionStrings.  

Something like:

 

<connectionStrings>
  <add name="LocalSqlServer" 
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient"/> </connectionStrings>

If you remove that entry from the machine.config then the Database Settings section should no longer appear.

 

For the curious: How does the configuration tool know what sections to display?  First it gets a list of all loaded assemblies.  Then it checks this list against any Enterprise Library configuration section registered handlers.  Next the tool does another check to see if that section exists and if it does it displays that section in the configuration tool.  The Data Access Application Block handles the dataConfiguration and connectionStrings sections so when the connectionStrings section appears in machine.config it causes the tool to display the Database Settings.

 

Randy