企业库4数据配置标签 [英] Enterprise library 4 dataconfiguration tag
问题描述
我正在使用企业库进行数据访问. 当我运行应用程序时,在CreateDatabase()语句中,我遇到了以下异常:
I am using Enterprise library for my data access. When I am running the application, at the CreateDatabase() statement I am getting this exception:
Microsoft.Practices.ObjectBuilder2.BuildFailedException 用户代码未处理 Message =当前的构建操作 (构建密钥Build 密钥[Microsoft.Practices.EnterpriseLibrary.Data.Database, null])失败: 该值不能为null或空字符串. (策略类型为Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy, 索引2)" Source ="Microsoft.Practices.ObjectBuilder2"
Microsoft.Practices.ObjectBuilder2.BuildFailedException was unhandled by user code Message="The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.Data.Database, null]) failed: The value can not be null or an empty string. (Strategy type Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder.ConfiguredObjectStrategy, index 2)" Source="Microsoft.Practices.ObjectBuilder2"
现在,我在Google上搜索了一下,发现必须放置
Now, I googled a bit and I found that I have to place
<dataConfiguration defaultDatabase="LocalSqlServer"/>
但是我不知道在哪里.这是正确的解决方案吗?
but I don't know where. Is it the right solution?
此外,在安装企业库时,我没有看到任何连接字符串语句?因此,我想知道它将如何从web.config文件中获取连接字符串.
Also, at the time of installing enterprise library I didn't see any connection string statement? So, I wonder how it will take the connection string from web.config file.
在我的web.config文件的连接字符串部分中,我有:
In the connection string section of my web.config file I have:
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=MSTR;Initial Catalog=USERDb;Integrated Security=true;" providerName="System.Data.SqlClient"/>
推荐答案
是的,您需要将dataConfiguration
部分添加到web.config.
Yes you need to add the dataConfiguration
section to the web.config.
首先,您需要将dataConfiguration添加到web.config中的ConfigurationSections列表中:
First you need to add dataConfiguration to the list of ConfigurationSections in your web.config:
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</configSections>
然后,您需要将连接字符串添加到web.config中(您已经完成了此操作):
Then you need to add your connection strings to the web.config (you've already done this):
<connectionStrings>
<add name="LocalSqlServer" connectionString="Data Source=MSTR;Initial Catalog=USERDb;Integrated Security=true;" providerName="System.Data.SqlClient"/>
</connectionStrings>
然后,您需要将实际的dataConfiguration部分添加到web.config中:
Then you need to add the actual dataConfiguration section to the web.config:
<dataConfiguration defaultDatabase="LocalSqlServer"/>
您还可以使用企业库配置工具为您执行此操作.
You can also use the Enterprise Library Configuration Tool to do this for you as well.
这篇关于企业库4数据配置标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!