我正在尝试在我的本地环境中执行以下代码片段并且它正常工作。但是当我尝试在其他系统中的更高环境中执行时,我遇到了运行时错误。以下是一块code.I我正在使用企业库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相关的内容。可以帮我解决一些替代解决方案