无聊的天空

天无绝人之路

导航

开始学习 Enterprise Library 3.1

Posted on 2008-04-07 22:43  无聊的心  阅读(258)  评论(0)    收藏  举报

      很早就有个朋友告诉我过Enterprise Library,去年下半年时也看了一下,不过一直没有深入学下去,当时就感觉通过Enterprise Library中的组件可以省出开发中的很多事情,最常用的就是那个Data Access Application Block ,开发中谁都要用到的;所以这次再看,第一个就是要学会用DAAB;
     晚上看了一下不是很复杂,第一步通过Configuration Tools建一个 ConnectionString 有以几种方式
To configure the default database

  1. In the right pane, expand the DefaultDatabase property.
  2. Enter the connection string name for the DefaultDatabase property or select it from the dropdown box. The default connection string name is ConnectionString.
  3. (Optional) Set the Name property by typing a new name. The default name is ConnectionString.
  4. In the ProviderName property section, change the provider name if you want to. Enter the name of the provider or select it from the drop-down list. The default provider name is System.Data.SqlClient. The ProviderName property must be a provider name specified in a DBProviderFactory class.

To configure a connection string

  1. Click the ConnectionString node.
  2. (Optional) Set the Name property by typing a new name. This is the name of the ConnectionString node. The default name is ConnectionString.
  3. (Optional) In the ProviderName property section, change the provider name. Enter the name of the provider or select it from the drop-down list. The default provider name is System.Data.SqlClient. The ProviderName property must be a provider name specified in a DbProviderFactory class.
  4. Update the ConnectionString property with the following value:
      Copy Code
    Database=Database;Server=(local)\SQLEXPRESS;Integrated Security=SSPI
                    

To configure SQL Server CE

  1. Right-click Custom Provider Mappings, point to New, and click Provider Mapping.
  2. Click on the Name property entry in the Properties pane. From the drop down list select Microsoft.SqlServerCe.Client.
  3. Click in the TypeName property entry in the Properties pane. Click the ellipsis (…) button.
  4. In the Type Selector, locate and double-click on SqlCeDatabase.
  5. Right-click on the ConnectionStrings node and click New, then Connection String
  6. (Optional) Set the Name property by typing a new name. This is the name of the ConnectionString node. The default name is ConnectionString.
  7. In the ProviderName property section, change the provider name to Microsoft.SqlServerCe.Client.
  8. In the ConnectionString property section, enter the desired SQL Server CE connection string, for example:
      Copy Code
    Data Source='C:\MyApp\MyDatabase.sdf'
                    

To configure an Oracle package

  1. Right-click ConnectionString, point to New, and then click OraclePackages.
  2. Click OraclePackage.
  3. Change the Name property by entering the name of the Oracle package. The default is OraclePackage.
  4. Enter a value for the Prefix property.

 

The next procedure explains how to add custom provider mappings by associating a provider with the fully qualified name of a database.

To configure a custom provider

  1. Right-click the CustomProviderMappings node, point to New, and then click ProviderMapping.
  2. (Optional) Set the Name property by typing a new name. Enter the name of the provider or select it from the drop-down list. The default provider name is System.Data.SqlClient. The ProviderName property must be a provider name specified in a DbProviderFactory class.
  3. In the TypeName property section, click the ellipsis button (…) and use the Type Selector to select the fully qualified name of the Enterprise Library Database type.
Server=(local)\SQLEXPRESS 这是SQL2005使用的连接字符串,