InvalidOperationException

Topics: Data Access Application Block
Mar 14, 2011 at 12:34 PM

Error 1

Resolution of the dependency failed, type = "Microsoft.Practices.EnterpriseLibrary.Data.Database", name = "ERequest".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value.

when using the line

private readonly Database _database = EnterpriseLibraryContainer.Current.GetInstance<Database>("ERequest");

Error 2

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)

when using the line

private readonly Database _database = EnterpriseLibraryContainer.Current.GetInstance<Database>();

 

using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;

 namespace hizkiel.ERequest.Services.DataAccessServices
{
    public class ModuleDatabase : IDatabase
    {
       // private readonly Database _database = DatabaseFactory.CreateDatabase();


//1

        private readonly Database _database = EnterpriseLibraryContainer.Current.GetInstance<Database>("ERequest");
 

//2 

             
        // private readonly Database _database = EnterpriseLibraryContainer.Current.GetInstance<Database>();

 

        public DbCommand GetStoredProcCommand(string storedProcedureName)
        {
        
            return _database.GetStoredProcCommand(storedProcedureName);
        }

        public void AddInParameter(DbCommand command, string name, DbType dbType, object value)
        {
            _database.AddInParameter(command, name, dbType, value);
        }

        public IDataReader ExecuteReader(DbCommand command)
        {
            return _database.ExecuteReader(command);
        }

        public void AddOutParameter(DbCommand command, string name, DbType dbType, int size)
        {
            _database.AddOutParameter(command, name, dbType, size);
        }

        public object GetParameterValue(DbCommand command, string name)
        {
            return _database.GetParameterValue(command, name);
        }

        public void ExecuteNonQuery(DbCommand command)
        {
            _database.ExecuteNonQuery(command);
        }
    }
}

Mar 14, 2011 at 11:54 PM

If you're referencing the Microsoft.Practices.EnterpriseLibrary.Data assembly from GAC, the exception you're encoutering is a known issue in EntLib 5.0.  Please refer to this item in the Issue Tracker for the workaround.

If this doesn't apply to you, could you post your ERequest connection string? 

 

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