A type database cannot be built. You must configure the container to deliver this value (EntLib 5 + ODP.NET)

I use ODP.NET and version 4.1 of the Enterprise Library, against 2008. And all is well.

Now navigate using ODP.NET Oracle.DataAccess 4.112.2.0 and version 5.0.414.0 from Enterprise Library, vs 2010, .net 4.0.

Oracle.DataAccess 4.112.2.0 EnterpriseLibrary 5.0.414.0

After a recent upgrade from version 4.1 to 5.0 in the corporate library, we get the following error:

"The type database cannot be constructed. You must configure the container to provide this value."

Microsoft.Practices.ServiceLocation.ActivationException: activation error occurred while trying to get an instance of type Database, key "ConnectionStrings.Oracle.xxx" ---> Microsoft.Practices.Unity.ResolutionFailedException: resolving dependency error, type = "Microsoft.Practices.EnterpriseLibrary .Data.Database ", name =" ConnectionStrings.Oracle.xxx ". An exception occurred during: while resolution. Exception: InvalidOperationException - The database type cannot be built. You must configure the container to deliver this value.

Links EntLib Forum: http://entlib.codeplex.com/discussions/215290

any decision on this?

my config

<configSections> <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=709072f976b4c05b"/> <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=709072f976b4c05b" /> </configSections> <dataConfiguration defaultDatabase="ConnectionStrings.Oracle.xxx"/> <connectionStrings> <add name="ConnectionStrings.Oracle.xxx" connectionString="DATA SOURCE=des;PASSWORD=zzz;PERSIST SECURITY INFO=True;USER ID=aaa;" providerName="Oracle.DataAccess.Client" /> 

My code

  var key = "ConnectionStrings.Oracle.xxx"; Database db = Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.Current.GetInstance<Database>(key); //~(EntLib 5 recommended) using (DbCommand cm = db.GetStoredProcCommand("TBL_FRKDATA.TBL_FRKDATA_FND_ALL")) { cm.Parameters.Add(CreateCursorParameter("P_REFCURSOR")); // Using "using" will cause both the DataReader and connection to be // closed. (ExecuteReader will close the connection when the // DataReader is closed.) using (IDataReader dataReader = db.ExecuteReader(cm)) { while (dataReader.Read()) { builder.Add(dataReader); } return builder.EntityList; } } 

full stacktrace error

Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive (IBuilderContext context, SelectedConstructor selectedConstructor) Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp (IBuilderContext context) Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp (IBuilderContext context) Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy. CreatePlan (IBuilderContext context, NamedTypeBuildKey buildKey) Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp (IBuilderContext context) Microsoft.Practices.ObjectBuilderUpon.Tenet.bnect.pect String name, IEnumerable 1 resolverOverrides) Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable 1 resolverOverrides) Microsoft.Practices.Unity.UnityConta iner.Resolve (Type t, string name, ResolverOverride [] resolverOverrides) Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance (Type serviceType, String) Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance (Type serviceTyPocation.Service) .ServiceLocatorImplBase.GetInstance (type serviceType, String) Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance [TService] (String key)

UPDATE

this code works for me:

  [TestMethod] public void Conectar_con_EntLib_y_OdpNet_Test() { var key = "ConnectionStrings.Oracle.xxx"; string connectionString = ConfigurationManager.ConnectionStrings[key].ConnectionString; string providerName = ConfigurationManager.ConnectionStrings[key].ProviderName; //Database db = Microsoft.Practices.EnterpriseLibrary.Common.Configuration.EnterpriseLibraryContainer.Current.GetInstance<Database>(key); TestContext.WriteLine("connectionString: " + connectionString); TestContext.WriteLine("providerName: " + providerName); DbProviderFactory factory = DbProviderFactories.GetFactory(providerName); using (DbConnection connection = factory.CreateConnection()) { connection.ConnectionString = connectionString; connection.Open(); TestContext.WriteLine("Estado Conexiรณn: " + connection.State); connection.Close(); } } 

Solution: Randy Levy ( http://entlib.codeplex.com/discussions/215290 )

You cannot use the OracleDatabase Enterprise Database with the Oracle.DataAccess.Client provider. The built-in OracleDatabase is tightly bound to use the OracleClientFactory DbProviderFactory, while you want to use the ODP.NET provider (Oracle.DataAccess.Client).

The best way is to get the Oracle ODP.NET EntLibContrib provider Data Data Provider, as it should support everything you need, including configuration files.

Since it looks like you can create a DbProviderFactory, you can try to use GenericDatabase with ODP.NET OracleClientFactory, but I would suggest that you run into problems for specific Oracle functionality (e.g. refcursor).

You can use it directly:

 string connectionString = ConfigurationManager.ConnectionStrings["Connection String"].ConnectionString; string providerName = ConfigurationManager.ConnectionStrings["Connection String"].ProviderName; DbProviderFactory factory = DbProviderFactories.GetFactory(providerName); var db = new GenericDatabase(connectionString, factory); 
+7
source share
2 answers

Add link to

 Microsoft.Practices.EnterpriseLibrary.Common Microsoft.Practices.EnterpriseLibrary.Data Microsoft.Practices.ServiceLocation 

then use this line to get the database:

 var database = EnterpriseLibraryContainer.Current.GetInstance<Database>(); 

Further information here: http://devstuffs.wordpress.com/2012/03/13/enterprise-library-5-with-odp-net/

+2
source

I had the same problem and decided to change the Enable 32-bit Applications application pool to true.

0
source

All Articles