In one compute works well, in other not work

Topics: Data Access Application Block
Sep 27, 2013 at 7:09 AM
Edited Sep 27, 2013 at 7:12 AM
I used enterprise library in my work. Now I have an issue. My project works well in my computer, but when I copy it to other computer, it doesn't work. Error info follow:

Microsoft.Practices.ServiceLocation.ActivationException: Activation error occured while trying to get instance of type Database, key "" ---> Microsoft.Practices.Unity.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)
---> System.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) 位置 e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs:行号 289
在 Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context) 位置 e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\Creation\DynamicMethodConstructorStrategy.cs:行号 71
在 Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) 位置 e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:行号 110
在 Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey) 位置 e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\DynamicMethod\DynamicMethodBuildPlanCreatorPolicy.cs:行号 48
在 Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context) 位置 e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\BuildPlan\BuildPlanStrategy.cs:行号 37
在 Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context) 位置 e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\ObjectBuilder\Strategies\StrategyChain.cs:行号 110
在 Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable1 resolverOverrides) 位置 e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:行号 511
--- 内部异常堆栈跟踪的结尾 ---
在 Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable
1 resolverOverrides) 位置 e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:行号 515
在 Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name, IEnumerable`1 resolverOverrides) 位置 e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:行号 485
在 Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name, ResolverOverride[] resolverOverrides) 位置 e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityContainer.cs:行号 173
在 Microsoft.Practices.Unity.UnityServiceLocator.DoGetInstance(Type serviceType, String key) 位置 e:\Builds\Unity\UnityTemp\Compile\Unity\Unity\Src\UnityServiceLocator.cs:行号 64
在 Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) 位置 c:\Home\Chris\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:行号 49


can anyone give a help?
Sep 27, 2013 at 8:50 AM
An InvalidOperationException usually indicates that there is a configuration issue. Have you setup the app.config / web.config? It should look something like this:
<configuration>
    <configSections>
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.505.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
    </configSections>
    <dataConfiguration defaultDatabase="Connection String" />
    <connectionStrings>
        <add name="Connection String" connectionString="Database=Database;Server=(local);Integrated Security=SSPI"
            providerName="System.Data.SqlClient" />
    </connectionStrings>
</configuration>

Some other cause might be that the DbProviderFactories might not be set up in machine.config (but I haven't seen this for SqlClient before), or use of Enterprise Library from the GAC.

If that doesn't help then can you provide more information around the specific scenario with code and configuration or perhaps a small sample application that reproduces the issue.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Sep 27, 2013 at 9:10 AM
I will try what you say. I post my web.config follow:

<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"/>
<section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
</configSections>
<dataConfiguration defaultDatabase="EnterpirseToMySql"/>
<connectionStrings>
<add name="EnterpirseToMySql" connectionString="server=192.168.18.222;user id=root;password=yuyue1!2@3#2013ABC;database=yyhmp" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>

Works well in my computer.
Sep 27, 2013 at 10:01 AM
try as you say , I resolved by add the DbProviderFactories in the web.config. My computer installs mysql, seems it adds mysql DbProviderFactories default.

Thanks very much.
Marked as answer by randylevy on 10/7/2013 at 10:55 PM