Visual Studio 2010 Web App Data Error

Topics: Data Access Application Block
Jul 30, 2010 at 3:34 AM

I am trying to setup a basic test web application project in visual studio 2010 using the Enterprise Library 5.0 with the 4.0 framework.

I have existing applications that use the library no worries at all in VS 2008 using the 3.5 framework.

The issue I am having is that the library seems to not look at my web.config file. 

Me.db = DatabaseFactory.CreateDatabase() 

Me.db = DatabaseFactory.CreateDatabase("STintranet")

both fail with he following exception:

Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type Database, key "" ---> Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value.

My web.config:

<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data"/>
<dataConfiguration defaultDatabase="STintranet"/>
<add name="STintranet" connectionString="Data Source=.;Initial Catalog=STintranet;Persist Security Info=True;User ID=***;Password=***" providerName="System.Data.SqlClient"/>
<compilation debug="true" strict="false" explicit="true" targetFramework="4.0" />
Jul 30, 2010 at 3:59 AM

Are you referencing the Data assembly from GAC? (Copy Local = false)  If yes, there's an issue regarding that and it's described here.  The workaround is included as well.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

Jul 30, 2010 at 4:22 AM

That was exactly my problem. I quickly tried the workaround with no luck, but for my purposes Copy local = true will suffice.