Activation error occured while trying to get instance of type Database, key "..."

Topics: General discussion
Oct 26, 2010 at 3:45 PM

In VS2010, I write a statement like this:

Database CPData = EnterpriseLibraryContainer.Current.GetInstance<Database>("CPData");

But, when running, an error displayed: Activation error occured while trying to get instance of type Database, key "CPData"?

I've created a Elib Config file for .NET 4 (using OleDB).
Pls tell me what wrong and how to fix it? Thanks a lot.

Oct 26, 2010 at 11:17 PM

Here are the possible reasons if you're sure you didn't passed the incorrect database instance name (CPData):

1.  You have your configuration file under a class library project.  Class libraries don't own configuration files so it should always be part of an executable project.

2.  You are referencing the Microsoft.Practices.EnterpriseLibrary.Data assembly from GAC.  Check the CopyLocal property of your Data reference; if it is set to False, then the CLR is trying to load it from GAC.  Change it to True if you do not really intend to reference from GAC.   If on the other hand, you really need it to be, there's a workaround posted in this workitem.

3.  The Database Provider property (or providerName attribute) is not set.  Make sure it's set to System.Data.OleDb.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com