The type Database cannot be constructed. You must configure the container to supply this value.

Topics: Data Access Application Block
Aug 17, 2010 at 8:25 PM
Edited Aug 17, 2010 at 8:36 PM

hi all,

I m trying to use the Database module of Entrprise library for my web application in VS2010. I have a web application in which i have some web service. in that applications web.config i have added the configuration as shown below. 

  <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" />
<dataConfiguration defaultDatabase="Constr" />
  <add name="Constr" connectionString="Server=DB-SErver;Database=DBName;uid=User;pwd=Password;"
   providerName="System.Data.SqlClient" />

i wrote the following code in a DLL which is refered in the web application.
	SqlDB = EnterpriseLibraryContainer.Current.GetInstance<Database>("Constr");
when executing the code it throws the following error.

Activation error occured while trying to get instance of type Database, key "Constr"
whats the mistake i m doing i couldnt figure it out. pls help me. 
Aug 18, 2010 at 2:50 AM

I wasn't able to reproduce the error encountered. Could you post the full exception you have encountered here. Also, how are you referencing from the Data assembly? Any chance that you're referencing it from GAC and probably encountering this issue.

Gino Terrado
Global Technology and Solutions
Avanade, Inc.

Aug 27, 2010 at 9:25 PM

I had solved the problem, as i configured the configuration in webservice's config file but the web service is refered as a reference and not as web reference as both the webservice and the presentation lies in the same machine now..