• Enterprise Library: Data Access Application Block配置文件分析篇


    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=1.0.0.0, Culture=neutral, PublicKeyToken=null" />

      </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/08-31-2004/configuration">

      <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=1.0.0.0, Culture=neutral, PublicKeyToken=null">

        <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/08-31-2004/data">

          <databaseTypes>

            <databaseType name="Sql Server" type="Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase, Microsoft.Practices.EnterpriseLibrary.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />

          </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. Enterprise Library: Data Access Application Block Quick Start

    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

     

     

  • 相关阅读:
    Nexus入门指南(图文)[转]
    java注解[转]
    JS设置IE可信站点及ActiveX设置
    ExtJS 4 树
    SQL大全
    基于Spring aop 和JAVA注解方式添加日志
    Excle自动增长序号
    VS 生成后事件
    Oracle命令分解之正则表达式搜索(一)
    Oracle命令分解之……SOUNDEX
  • 原文地址:https://www.cnblogs.com/rickie/p/102984.html
Copyright © 2020-2023  润新知