Enterprise Library-Data Access Application Block learning Manual (Latest Version)-Part 1

Source: Internet
Author: User
Tags connectionstrings
Enterprise Library. net Framework 3.5-entlib v4.1 is the patterns & Practices Group. net Framework 3.5 is used to develop a set of Enterprise libraries. The latest version is v4.1, which includes 9 Application blocks, including data access application blocks and Exception Handling application blocks) validation Application Block is very helpful and practical for enterprise application development. Http://blog.entlib.com/EntLib/archive/2009/03/30/enterprise-library-for-.net-framework-3.5-entlib-v4.1-v4.1.aspx this article according to the entlib v4.1 learning Manual (hands on Lab), demonstrates the application of the data access module: 1. download the hands on Lab (http://www.codeplex.com/entlib) of entlib v4.1 and install it. Open the simpledata. sln project file of \ Enterprise Library 4.1 Hol \ CS \ data access \ exercises \ ex01 \ begin under the installation directory to start the following work. Before starting, you also need to create the entlibquickstarts Database accessed in the sample program. Script file for creating databases, tables, and stored procedures: Enterprise Library 4.1 Hol \ CS \ data access \ Setup \ dataaccessquickstarts. SQL. Open it in SQL Server 2005/2008 and execute it. 2. reference the DLL file required by entlib. In the installation directory, c: \ Program Files \ Microsoft Enterprise Library 4.1-October 2008 \ bin. Here, the following DLL file is referenced: Microsoft. practices. enterpriselibrary. common. dllmicrosoft. practices. enterpriselibrary. data. DLL to open mainform. CS code file, add the application namespace reference: using Microsoft. practices. enterpriselibrary. data; 3. add code: the first code shows how many MERs records are returned. Private void mnucount_click (Object sender, system. eventargs e) {database DB = NULL; DB = databasefactory. createdatabase ("quickstarts instance"); int COUNT = (INT) dB. executescalar (commandtype. text, "select count (*) from MERs"); string message = string. format ("there are {0} MERs in the Database", Count. tostring (); MessageBox. show (Message);} The second code is to return all the MERs records and display them in the DataGrid. Private void mnuload_click (Object sender, system. eventargs e) {database DB = NULL; DB = databasefactory. createdatabase (); dataset DS = dB. executedataset (commandtype. text, "select * from MERs"); datagrid1.datasource = Ds. tables [0];} so far, the above Code cannot be run, because app. the config file has not been created, and no database connection exists. 4. Create the app. config configuration file and edit it using the editor attached to entlib. The corresponding configuration file is automatically generated, as shown in. The editor is integrated with Visual Studio 2008. As shown in, use the editor to create a new connection string.
 
Set the connection string information.
Note: (1) Select the connection string node and change the name attribute to quickstarts instance, which is the parameter value passed in when the database is created in the above Code. (2) Select the Data Access Application Block node and set the defaultdatabase attribute to quickstarts instance. In the second code above, no parameter is input when the database object is created, that is, the defaultdatabase parameter defined here. Save the preceding configuration information and check the automatically generated configuration file: <? Xmlversion = "1.0" encoding = "UTF-8"?> <Configuration> <configsections> <sectionname = "dataconfiguration" type = "Microsoft. practices. enterpriselibrary. data. configuration. databasesettings, Microsoft. practices. enterpriselibrary. data, version = 4.1.0.0, culture = neutral, publickeytoken = 31bf3856ad364e35 "/> </configsections> <dataconfigurationdefadatabase database =" Quickstarts instance"/> <Connectionstrings> <addname =" Quickstarts instance"Connectionstring =" Data Source = yourcomputername; initial catalog = entlibquickstarts; Integrated Security = true "providername =" system. data. sqlclient "/> </connectionstrings> </configuration> 5. now you can run the sample program to check the running status. You are welcome to continue accessing the subsequent content.

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.