4
votes

I am using Enterprise library for my data access. When I am running the application, at the CreateDatabase() statement I am getting this exception:

Microsoft.Practices.ObjectBuilder2.BuildFailedException was unhandled by user code Message="The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.Data.Database, null]) failed: The value can not be null or an empty string. (Strategy type Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy, index 2)" Source="Microsoft.Practices.ObjectBuilder2"

Now, I googled a bit and I found that I have to place

<dataConfiguration defaultDatabase="LocalSqlServer"/>

but I don't know where. Is it the right solution?

Also, at the time of installing enterprise library I didn't see any connection string statement? So, I wonder how it will take the connection string from web.config file.

In the connection string section of my web.config file I have:

<remove name="LocalSqlServer"/>
 <add name="LocalSqlServer" connectionString="Data Source=MSTR;Initial Catalog=USERDb;Integrated Security=true;" providerName="System.Data.SqlClient"/>
1

1 Answers

6
votes

Yes you need to add the dataConfiguration section to the web.config.

First you need to add dataConfiguration to the list of ConfigurationSections in your web.config:

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

Then you need to add your connection strings to the web.config (you've already done this):

<connectionStrings>
    <add name="LocalSqlServer" connectionString="Data Source=MSTR;Initial Catalog=USERDb;Integrated Security=true;" providerName="System.Data.SqlClient"/>      
</connectionStrings>

Then you need to add the actual dataConfiguration section to the web.config:

<dataConfiguration defaultDatabase="LocalSqlServer"/>

You can also use the Enterprise Library Configuration Tool to do this for you as well.