Learn the Microsoft Enterpriselibrary 5.0 Data Access Application Block

Source: Internet
Author: User
Tags connectionstrings

Microsoft provides developers with an enterprise library for error handling, logging, AOP, database access, permission control, and more. The database access module is used here to implement database access to SQL Server.

First open the EntLibConfig.exe configuration program under the installation directory and select Add Data Settings

You can set the connection string name, the connection string content, and the type of connection database. Set to save as a profile later, the contents of the configuration file are:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Configuration>3   <configsections>4     < Sectionname= "Dataconfiguration"type= "Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, version=5.0.414.0, culture=neutral, publickeytoken=31bf3856ad364e35 " requirepermission= "true" />5   </configsections>
<--! Configure the default connection string name--6 <dataconfigurationDefaultDatabase= "ConnStr" />7 <connectionStrings>8 <Addname= "ConnStr"connectionString= "Data source=.;i Nitial catalog=tsinghua;integrated security=true "9 ProviderName= "System.Data.SqlClient" />Ten </connectionStrings> One </Configuration>

When the configuration is complete, The introduction of Microsoft.Practices.EnterpriseLibrary.Data.dll and Microsoft.Practices.EnterpriseLibrary.Data.SqlCe.dll two files. So the environment is built.

Before you perform a database operation, you need to create a DB class that creates the following method:

// the default connection string in configuration information Database db = databasefactory.createdatabase (); // using the custom connection string Database db = Databasefactory.createdatabase ("connstr");


In this way, you can invoke various methods in the DB object to manipulate the database, and all methods will be prompted at the time of the call, and this will not be discussed here.


Learn the Microsoft Enterpriselibrary 5.0 Data Access Application Block

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.