Enterprise Library: Data Access Application Block配置文件分析篇
Written by: Rickie Lee (rickieleemail#yahoo.com)
My blog: www.cnblogs.com/rickie
Enterprise Library提供了Configuration Console配置工具,用来编辑或查看配置文件信息,调用DAAB的应用程序一般会使用Configuration Console工具产生两个文件:App.config(Web.config)和DataConfiguration.config,其中App.config(Web.config)一般有VS.NET添加进来,然后由Configuration Console进行编辑,DataConfiguration.Config则在通过Configuraiton Console编辑App.config(Web.config)配置文件时,默认生成的数据连接配置文件,与App.config(Web.config)在同一目录。
App.config文件包含配置元数据,DAAB的配置信息在DataConfiguration.config文件中。如下是App.config示例:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="enterpriselibrary.configurationSettings" type="Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationManagerSectionHandler, Microsoft.Practices.EnterpriseLibrary.Configuration, Version=
</configSections>
<enterpriselibrary.configurationSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" applicationName="Application" xmlns="http://www.microsoft.com/practices/enterpriselibrary/
<configurationSections>
<configurationSection xsi:type="ReadOnlyConfigurationSectionData" name="dataConfiguration" encrypt="false">
<storageProvider xsi:type="XmlFileStorageProviderData" name="XML File Storage Provider" path="dataConfiguration.config" />
<dataTransformer xsi:type="XmlSerializerTransformerData" name="Xml Serializer Transformer">
<includeTypes />
</dataTransformer>
</configurationSection>
</configurationSections>
<keyAlgorithmStorageProvider xsi:nil="true" />
<includeTypes />
</enterpriselibrary.configurationSettings>
</configuration>
上述App.config配置元数据文件包含如下信息:
Configuration Section名称: enterpriselibrary.configurationSettings
Storage Provider: XmlFileStorageProviderData及其配置文件路径dataConfiguration.config
Data Transformer: XmlSerializerTransformerData
如下是dataConfiguration.config配置文件:
<?xml version="1.0" encoding="utf-8"?>
<dataConfiguration>
<xmlSerializerSection type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=
<enterpriseLibrary.databaseSettings xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" defaultInstance="Database Instance" xmlns="http://www.microsoft.com/practices/enterpriselibrary/
<databaseTypes>
<databaseType name="Sql Server" type="Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=
</databaseTypes>
<instances>
<instance name="Database Instance" type="Sql Server" connectionString="Sql Connection String" />
</instances>
<connectionStrings>
<connectionString name="Sql Connection String">
<parameters>
<parameter name="database" value="Northwind" isSensitive="false" />
<parameter name="Integrated Security" value="False" isSensitive="false" />
<parameter name="User ID" value="sa" isSensitive="false" />
<parameter name="Password" value="yourpassword" isSensitive="true" />
<parameter name="server" value="localhost" isSensitive="false" />
</parameters>
</connectionString>
</connectionStrings>
</enterpriseLibrary.databaseSettings>
</xmlSerializerSection>
</dataConfiguration>
上述配置文件包含如下信息:
数据库类型: SQL Server
Database Server: localhost
Database Name: Northwind
数据库实例名: Database Instance
连接字符串: Sql Connection String
另外,在连接字符串中添加了User ID, Password等属性及其属性值, Integrated Security设置为False。
***
作者:Rickie Lee (rickieleemail#yahoo.com)
本文参考Microsoft patterns & practices Enterprise Library文档。
References:
1.
2. Rickie, Microsoft patterns & practices Enterprise Library January 2005 [中文稿], http://www.cnblogs.com/rickie/archive/2005/01/30/99443.html
3. Rickie, Enterprise Library released! http://www.cnblogs.com/rickie/archive/2005/01/29/99106.html