locked
activation error occured while trying to get instance of type database key through connectionstring RRS feed

  • Question

  • User-266166614 posted

    <div class="markDownOutput ">When calling this property, I am receive error activation error occured while trying to get instance of type database key through connectionstring.
    I am using Enterprise Library 5.0


    public static Database Database

    public static Database

    Database

     

    public static Database

     

     

    public static Database Database
    
    {
            get
            {
                return DatabaseFactory.CreateDatabase();
            }
        }

    relevant part of web.config --
    <configSections>

    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true"/>
    <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="Q"/>
    <connectionStrings>

    <add name="Q" connectionString="Data Source=DV;Initial Catalog=QUA;UID=sa;pwd=AAA" providerName="System.Data.SqlClient"/>
    <add name="T" connectionString="Data Source=DV;Initial Catalog=QuanT;UID=sa;pwd=AAA" providerName="System.Data.SqlClient"/>
    <add name="P" connectionString="Data Source=DV;Initial Catalog=QuaP;UID=sa;pwd=AAA" providerName="System.Data.SqlClient"/>

    </connectionStrings>

    please note same code work perfectly fine all the time when executing through Visual Studio Built in Web Server but when I published in IIS and executing through IIS, I got this error..</div>

    Thursday, March 19, 2015 12:10 PM

Answers

  • User-266166614 posted

    This has been resolved, Issue was in Visual Studio Publishing Feature, Which was not copying web.config when publishing. This is really surprising.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 30, 2015 6:39 AM

All replies

  • User-266166614 posted

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

    Below is Stack Trace

    [InvalidOperationException: The type Database cannot be constructed. You must configure the container to supply this value.]
       Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor) +277
       Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) +485
       Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +434
       Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey) +400
       Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +222
       Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +434
       Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +440

    [ResolutionFailedException: 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)
    ]
       Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +546
       Microsoft.Practices.Unity.UnityCo[InvalidOperationException: The type Database cannot be constructed. You must configure the container to supply this value.]
       Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor) +277
       Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) +485
       Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +434
       Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey) +400
       Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) +222
       Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) +434
       Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +440

    [ResolutionFailedException: 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)
    ]
       Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides) +546
       Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides) +20
       Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +70

    [ActivationException: Activation error occured while trying to get instance of type Database, key ""]
       WebUI.Default.Page_Load(Object sender, EventArgs e)ntainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides) +20
       Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +70

    [ActivationException: Activation error occured while trying to get instance of type Database, key ""]
       WebUI.Default.Page_Load(Object sender, EventArgs e)

    Thursday, March 19, 2015 12:25 PM
  • User-266166614 posted

    This has been resolved, Issue was in Visual Studio Publishing Feature, Which was not copying web.config when publishing. This is really surprising.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, March 30, 2015 6:39 AM