Connecting to SQL Database using Enterprise Library's Data Access block RRS feed

  • Question

  • Hello,
    I am creating a windows forms application in C# and I'm trying to connect to my SQL database using Enterprise Library's Data Access application block using the following code (btw, I'm sort of new to these forums and wasn't sure if there's specific way to mark code in a post, so i just changed the font and color):

    ConnectionStringSettings s =    ConfigurationManager.ConnectionStrings["myConnString"];

    Database DB = DatabaseFactory.CreateDatabase(s.ConnectionString);

    So I've created an App.config file defining my connection string, as seen below:

    <?xml version="1.0" encoding="utf-8" ?>
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=, Culture=neutral, PublicKeyToken=null" />
      <dataConfiguration defaultDatabase="TMGAccountMaintenance" />
        <add name="myConnString" connectionString="Database=myDbName;Server=myServerName;Trusted_Connection=yes;"
            providerName="System.Data.SqlClient" />

    Now, when I build, I get the following two Messages, and cannot connect to the database.

    Message    1    Could not find schema information for the element 'dataConfiguration'.      
    Message    2    Could not find schema information for the attribute 'defaultDatabase'.

    Any insight on how to fix this would be greatly appreciated, thanks!
    Friday, September 15, 2006 5:12 PM


All replies

  • Your config line:

    <dataConfiguration defaultDatabase="TMGAccountMaintenance" />

    says your defaultDatabase has a connectionstring called TMGAccountMaintenenance.

    You don't have a connectionstring called TMGAccountMaintenenance, so hence you will get an error when you try to connect to the database. Rename your connectionstring, called myConnString, to TMGAccountMaintenenance.

    If you use the Enterprise Library Configuration Tool bundled with Enterprise Library to configure the Data Access Application Block you won't accidentally misconfigure the block.

    I have a tutorial for the DAAB that shows you various ways to configure and use it:

    Enterprise Library 2.0 Data Access Application Block

    Here is a tutorial that gives more information on the configuration aspects:

    Enterprise Library 2.0 - From Configuration Block to IConfigurationSource - SystemConfigurationSource - FileConfigurationSource

    and another tutorial on using the configuration tool particularly for configuring the DAAB:

    Enterprise Library 2.0 Configuration Tool - Configuring Data Access Application Block

    Hope this helps,


    Saturday, September 16, 2006 12:38 AM
  • Thanks Dave.
    Though, in my actual code, I do have the names set correctly, I wanted to change them for posting on the forums, and I forgot to change the defaultDatabase. Sorry about that.   So with that, I still get the error, but I will look at the links you provided and see if I can't get anything from them.  I have tried using the Enterprise Library Configuration tool to configure the Data Access block, but I've still received the same errors each time.
    Monday, September 18, 2006 1:33 PM
  • So far I'm not having any luck.  I've even tried recreating the entire project, recreating the app.config file, and adding the enterprise library elements to my solution again, and I still get the messages.  One guess I have is that I'm not importing or referencing something that I should be?  When I double click the two messages, they take me to this line in the app.config file:

    <dataConfiguration defaultDatabase="myConnString" />

    btw, thanks for the links!  I actually came across the last one during a google search before posting here, and used it to set up the config file the first time.
    Monday, September 18, 2006 2:58 PM
  • I suggest opening up one of the DAAB quickstarts which are installed when you install Enterprise Library and see if you can get them to compile and run.

    As far as references, you need to reference 3 assemblies to get the Data Access Application Block to work correctly:

    1. Microsoft.Practices.EnterpriseLibrary.Common.dll
    2. Microsoft.Practices.EnterpriseLibrary.Data.dll
    3. Microsoft.Practices.ObjectBuilder.dll



    Monday, September 18, 2006 9:35 PM
  • Hi there

    I'm having the exact same problem. i've referenced and imported the common, data and objectbuilder dll's and i can see nothing wrong with my web.config file but i get the same messages as mentioned above

    1 could not find schema information for the element 'dataConfiguration'

    2 could not find schema information for the attribute 'defaultDatabase'



    Monday, February 19, 2007 12:38 PM
  • Let me chime in with the same problem...

    I am using Visual Studio 2005 with sp1 installed

    I just downloaded and installed the Enterprise Library.   The sample application built and tests properly.

    This is my first stab at my own implementation..

    <?xml version="1.0" encoding="utf-8" ?>





    type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" />


    <dataConfiguration defaultDatabase="OracleXE"/>


    <add key="provider" value="Oracle.DataAccess.Client"/>



    <add name="OracleXE" connectionString="User Id=SYSTEMS;Password=###########;DATA SOURCE=XE"/>




    with the following build errors

    Message 1 Could not find schema information for the element 'dataConfiguration'. C:\Documents and Settings\twalston\My Documents\Visual Studio 2005\Projects\Systems\Systems\App.config 14 4 Systems
    Message 2 Could not find schema information for the attribute 'defaultDatabase'. C:\Documents and Settings\twalston\My Documents\Visual Studio 2005\Projects\Systems\Systems\App.config 15 13 Systems


    I have references to













     --Followup Note.   These errors are informational errors.   My app does run and I do get data back.

    Friday, March 2, 2007 9:59 PM
  • Did any of you ultimately find a resolution to this?  These messages are informational warnings to me, but at runtime when I try to do a DatabaseFactory.CreateDatabase(); I get null returned.  I suspect the warnings and the problems are related.

    Did any of you successfully resolve or ignore these issues?
    Monday, May 21, 2007 10:25 PM
  • I too got the same error:

    • Could not finid schema information for the element 'dataConfiuration'
    • Could not finid schema information for the element 'defaultDatabase'

    I noticed that I didn't have (xmlns=http://schemas.microsoft.com/.NetConfiguration/v2.0) next to the Configuration node

    So I added the xmlns statement, the errors went away, but now I have 60 Warnings.


    here is what I have now:

    <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">



    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=, Culture=neutral, PublicKeyToken=null" />


    <dataConfiguration defaultDatabase="PCC_SQL_Connection" />



    <add name="MembershipConnection" connectionString="Data Source=BDC-intra665; Initial Catalog=aspnetdb; Persist Security Info=True;User ID=XXX;Password=XXXX' providerName="System.Data.SqlClient"/>

    <add name="PCC_SQL_Connection" connectionString="Data Source=BDC-intra665; Initial Catalog=PCC; Persist Security Info=True;User ID=XX;Password=XXXXXX" providerName="System.Data.SqlClient"/>



    I just checked my other projects that I've used this in, and they too have the same Warnings. So, maybe thats the solution, and we just deal with warnings.




    Friday, May 25, 2007 3:15 PM
  • Did you add the same dll (enterprise....) to the bin folder which you referenced? that is if you have the same dll in both your 'bin'  and 'reference', you might get a null issue with DatabaseFactory.CreateDatabase().
    Tuesday, February 24, 2009 1:57 AM
  • one solution might be that your web.confi file is open in IDE. close it and then try re-building the solution. hopefully it should solve you problem
    • Proposed as answer by Fabrikod Sunday, May 29, 2011 5:33 PM
    Thursday, August 27, 2009 5:05 PM