企业库5数据库连接失败 [英] Enterprise Library 5 database connectivity failure
问题描述
我收到以下错误:
类型无法构建数据库。您必须配置容器以提供此值。
异常详细信息:System.InvalidOperationException:无法构造数据库类型。您必须配置容器以提供此值。
Hi,
I'm receiving the following error:
The type Database cannot be constructed. You must configure the container to supply this value.
Exception Details: System.InvalidOperationException: The type Database cannot be constructed. You must configure the container to supply this value.
Source Error:
Line 168: public DataSet ExecuteDataSet(string strSpName, List<CommandParameter> objLstParameter = null, List<string> tableNames = null)
Line 169: {
Line 170: Database objDatabase = (Database)DatabaseFactory.CreateDatabase();
Line 171: using (DbConnection objDbConn = objDatabase.CreateConnection())
Line 172: {
以下是我添加的参考列表。
Microsoft.Practices.EnterpriseLibrary.Common.dll,Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.ServiceLocation。 dll
Microsoft.Practices.Unity.dll
Microsoft.Practices.Unity.Interception.dll
这里是我为解决方案创建的app.config:
Here are the list of references I have added.
Microsoft.Practices.EnterpriseLibrary.Common.dll, Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.ServiceLocation.dll
Microsoft.Practices.Unity.dll
Microsoft.Practices.Unity.Interception.dll
Here is the app.config that I've created for the solution:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<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" />
</configSections>
<dataConfiguration defaultDatabase="ConnectionString" />
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=xxxxxx; Persist Security Info=True;Initial Catalog = xxxx;user id = xxxxx; password = xxxx"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
请让我知道我在哪里制作错误。
Please let me know where I'm making mistake.
推荐答案
查看此帖子
InvalidOperationException - 无法构造数据库类型。您必须配置容器以提供此值。 [ ^ ]
并查看此讨论
MSDN - 无法构建类型数据库。您必须配置容器以提供此值。 [ ^ ]
Check this post
InvalidOperationException - The type Database cannot be constructed. You must configure the container to supply this value.[^]
And check this discussion
MSDN - "The type Database cannot be constructed. You must configure the container to supply this value." [^]
I resolved this error by doing the step below
From the NuGet Package Manager Console, run the following command:
Install-Package EntLibContrib.Data.OdpNet
这篇关于企业库5数据库连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!