Use postgres data provider with Enterprise Library 5.0

Topics: Data Access Application Block
May 27, 2010 at 5:19 PM

I have been trying to use the Postgresql data provider from EntLibContrib (entlibcontrib.codeplex.com) with Enterprise Library 5.0 and I had no success.  These are the contents of the configuration file I am using:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <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" />
  </configSections>
<dataConfiguration defaultDatabase="PGTest">
  <providerMappings>
    <add databaseType="EntLibContrib.Data.PostgreSql.NpgsqlDatabase, EntLibContrib.Data.PostgreSql, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null"
      name="Npgsql" />
  </providerMappings>
</dataConfiguration>
<connectionStrings>
  <add name="PGTest" connectionString="Server=localhost;Port=5432;Database=dbtest;User ID=postgres;Password=pwd;Enlist=true;"
    providerName="Npgsql" />
</connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>

Then I try to create a Database instance with the following code:

Database db = EnterpriseLibraryContainer.Current.GetInstance<Database>();

And I obtain the following exception:

Microsoft.Practices.ServiceLocation.ActivationException was unhandled
  Message=Activation error occured while trying to get instance of type Database, key ""
  Source=Microsoft.Practices.ServiceLocation
  StackTrace:
       at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 53
       at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService]() in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 90
       at ConsoleApplication1.Program.Main(String[] args) in D:\proyectos\SimForTree\software\ConsoleApplication1\ConsoleApplication1\Program.cs:line 14
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: Microsoft.Practices.Unity.ResolutionFailedException
       Message=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.
-----------------------------------------------
At the time of the exception, the container was:

  Resolving Microsoft.Practices.EnterpriseLibrary.Data.Database,(none)

       Source=Microsoft.Practices.Unity
       TypeRequested=Database
       StackTrace:
            at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 515
            at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 485
            at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 173
            at Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityServiceLocator.cs:line 64
            at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 49
       InnerException: System.InvalidOperationException
            Message=The type Database cannot be constructed. You must configure the container to supply this value.
            Source=Microsoft.Practices.Unity
            StackTrace:
                 at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs:line 289
                 at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs:line 71
                 at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:line 110
                 at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlanCreatorPolicy.cs:line 48
                 at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs:line 37
                 at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:line 110
                 at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) in e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:line 511
            InnerException:

Is there something wrong with the contents of the configuration file?  Everything was working fine with Enterprise Library 4.1.  Or probably is there a version conflict between PostgreSQL data provider and Enterprise Library 5.0?.  Is it possible to use the PostgreSQL data provider along with Enterprise Library 5.0, or should I get back to 4.1?  Any help will be highly appreciated.

Thanks.

May 27, 2010 at 7:40 PM

My understanding is that EntlibContrib is currently targeting Entlib 4.1 There are significant differences between Entlib 4.1 and 5.0, and code is not binary compatible between the two.

You'll need to ask the EntlibContrib team when / if they'll be updating to Entlib 5.

 

Feb 19, 2011 at 9:26 AM

Have solved this problem? If yes, pls let me know the answer.

I am also using Entlib 5.0 and getting same error but previously i have not installed any Entlib version on my system.

 

 

 

 

Feb 19, 2011 at 9:40 AM

The problem is that the Postgres data provider is not compatible with EntLib 5.0.  One solution could be to use the data provider with EntLib 4.1 (that is what  I have been doing so far), or to wait until a new version of the data provider compatible with EntLib 5.0 appears.

Mar 3, 2011 at 2:46 PM
Edited Mar 3, 2011 at 3:28 PM

I am facing the same issue but I am using IBM.DATA.DB2 as my Database Provider. Is it compatible with EntLib 5.0?

Mar 4, 2011 at 1:16 AM

I believe your concern is already answered in your other thread.

 

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