0

我正在尝试在我的本地环境中执行以下代码片段并且它工作正常。但是当我尝试在更高的环境中执行时,例如在其他系统中,我遇到了运行时错误。以下是一段代码。我我正在使用企业库 5。

internal static DataTable Users()
        {
            DataSet Users = null;
            string sqlStmt = ConfigurationManager.AppSettings["anyKey"];
            try
            {
                Database database = DatabaseFactory.CreateDatabase("Dbname");
                DbCommand command = database.GetSqlStringCommand(sqlStmt);
                using (command)
                {
                    Users = database.ExecuteDataSet(command);
                }
            }
            catch (Exception ex)
            {
                LoggerHelper.LogInformation("Error occured getting value");
                LoggerHelper.LogException(ex);
            }
            return dbname.Tables[0];

我得到的错误是:

[Error] Migration - Message: Activation error occured while trying to get instance of type Database, key ""; Activation error occured while trying to get instance of type Database, key ""
   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key)
   at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance[TService](String key)
   at Microsoft.Practices.EnterpriseLibrary.Data.DatabaseFactory.InnerCreateDatabase(String name)
   at Deloitte.PeopleNetwork.ImportUtility.DataLayer.Users()
Starting at: The type Database cannot be constructed. You must configure the container to supply this value.
   at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.GuardTypeIsNonPrimitive(IBuilderContext context, SelectedConstructor selectedConstructor)
   at Microsoft.Practices.ObjectBuilder2.DynamicMethodConstructorStrategy.PreBuildUp(IBuilderContext context)
   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
   at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlanCreatorPolicy.CreatePlan(IBuilderContext context, NamedTypeBuildKey buildKey)
   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)
   at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name, IEnumerable`1 resolverOverrides)

我已经检查了有关 dll 的所有内容。你能帮我一些替代解决方案吗

4

0 回答 0