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" >
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" />
</configSections>
<dataConfiguration defaultDatabase="TMGAccountMaintenance" />
<connectionStrings>
<add name="myConnString" connectionString="Database=myDbName;Server=myServerName;Trusted_Connection=yes;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
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'.
C:\Projects\projectname\App.config
Message 2 Could not find schema information for the attribute 'defaultDatabase'.
C:\Projects\projectname\App.config
Any insight on how to fix this would be greatly appreciated, thanks!

Connecting to SQL Database using Enterprise Library's Data Access block
Malleswar
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,
Dave
SenthilNathan
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.
DanielWiss
I too got the same error:
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"><
configSections><
section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null" /></
configSections><
dataConfiguration defaultDatabase="PCC_SQL_Connection" /><
connectionStrings><
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"/> </connectionStrings>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.
-rwiethorn
Matt Penfold
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
csharpdevelopernovice
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:
Regards,
Dave
Alba
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" >
<configuration>
<configSections>
<section
name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" /></
configSections><
dataConfiguration defaultDatabase="OracleXE"/><
appSettings><
add key="provider" value="Oracle.DataAccess.Client"/></
appSettings><
connectionStrings><
add name="OracleXE" connectionString="User Id=SYSTEMS;Password=###########;DATA SOURCE=XE"/></
connectionStrings></
configuration>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
Microsoft.Practices.EnterpriseLibrary.Common
Microsoft.Practices.EnterpriseLibrary.Data
Microsoft.Practices.ObjectBuilder
Oracle.DataAccess
System
System.Configuration
System.Data
System.Deployment
System.Drawing
System.Windows.Forms
System.Xml
--Followup Note. These errors are informational errors. My app does run and I do get data back.
beto81
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'
cheers
nick
debraj dhar
<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.