很早就有个朋友告诉我过Enterprise Library,去年下半年时也看了一下,不过一直没有深入学下去,当时就感觉通过Enterprise Library中的组件可以省出开发中的很多事情,最常用的就是那个Data Access Application Block ,开发中谁都要用到的;所以这次再看,第一个就是要学会用DAAB;
晚上看了一下不是很复杂,第一步通过Configuration Tools建一个 ConnectionString 有以几种方式
To configure the default database
- In the right pane, expand the DefaultDatabase property.
- Enter the connection string name for the DefaultDatabase property or select it from the dropdown box. The default connection string name is ConnectionString.
- (Optional) Set the Name property by typing a new name. The default name is ConnectionString.
- 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
- Click the ConnectionString node.
- (Optional) Set the Name property by typing a new name. This is the name of the ConnectionString node. The default name is ConnectionString.
- (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.
- Update the ConnectionString property with the following value:
Copy Code
Database=Database;Server=(local)\SQLEXPRESS;Integrated Security=SSPI
To configure SQL Server CE
- Right-click Custom Provider Mappings, point to New, and click Provider Mapping.
- Click on the Name property entry in the Properties pane. From the drop down list select Microsoft.SqlServerCe.Client.
- Click in the TypeName property entry in the Properties pane. Click the ellipsis (…) button.
- In the Type Selector, locate and double-click on SqlCeDatabase.
- Right-click on the ConnectionStrings node and click New, then Connection String
- (Optional) Set the Name property by typing a new name. This is the name of the ConnectionString node. The default name is ConnectionString.
- In the ProviderName property section, change the provider name to Microsoft.SqlServerCe.Client.
- 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
- Right-click ConnectionString, point to New, and then click OraclePackages.
- Click OraclePackage.
- Change the Name property by entering the name of the Oracle package. The default is OraclePackage.
- 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
- Right-click the CustomProviderMappings node, point to New, and then click ProviderMapping.
- (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.
- 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.
浙公网安备 33010602011771号