Contact
Send mail to the author(s) Email Me

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Sign In
Navigation

Tag Cloud
.NET Framework (31) AJAX (9) ASP.NET (16) ASP.NET MVC (3) C# (32) Cloud (2) Database (6) Dev Community (2) Dev Tools (5) Enterprise Library (1) Futures (2) General (6) Javascript (7) LINQ (2) Mobile (1) MSDTC (5) Quotes (3) SQL (3) Transactions (4) WAS (2) WCF (19) WIF (1) Visual Studio (3)

Archive
<February 2010>
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
28123456
78910111213

Categories

Blogroll
Home Feed your aggregator (RSS 2.0)
# Saturday, December 06, 2008

It's so easy! Start downloading Enterprise Library 4.1 now while you read this. The data application block syntax has not changed much since the first version. The most notable change was allowing us to use System.Data.Common.DbCommand when version 3.0 was released. I understand the uneasy feeling some developers have using Enterprise Library. My team at my previous employer decided not to use it, thinking it would add increased complexity and would not give us the flexibility we needed if we had to change something. This is typical of groups that do not have an established Data Access Library.

Your Data Access Library should be one of the most highly tested libraries in your application. If there is a problem there, you will have issues everywhere. Enterprise Library not only comes with the source code, but also includes the full suite of unit tests for each of the application blocks. You should feel at ease when you decide to migrate to Enterprise Library. Run it through your full battery of tests before you commit the team to it. If you find any problems, check the forums, request changes/enhancements from the MS Patterns & Practices team, or fix it yourself.

The steps to achieve EntLib goodness:

  1. Download Enterprise Library
  2. Add reference to "Enterprise Library Data Access Application Block" and "Enterprise Library Shared Library"
  3. Change your app.config or web.config
  4. Write some much more readable data access code

I'll start at step 3 as steps 1 and 2 are self-explanatory. Your connection string needs to be in you app's config file, the machine.config file, or in a connectionStrings.config file referenced in those config files. You can start using it just by adding the <configSections> clock and the <dataConfiguration> node. This will allow you to have one default database for all commands you will execute.

<?xml version="1.0" encoding="utf-8"?>

<configuration>

    <configSections>

        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

    </configSections>

    <dataConfiguration defaultDatabase="Testing" />

    <connectionStrings>

        <add name="Testing" connectionString="server=Server_Name;database=DB_Name;Integrated Security=true;"

                  providerName="System.Data.SqlClient" />

    </connectionStrings>
</configuration>

 

By the time you get to step 4, you have all of the infrastructure in place. Painless so far, let's see how steep the learning curve is.

With ADO.NET, you would write:

  116 string connectionString = ConfigurationManager.ConnectionStrings["Testing"].ConnectionString;

  117 using (SqlConnection con = new SqlConnection(connectionString))

  118 using (SqlCommand cmd = new SqlCommand("usp_ErrorLog_Insert", con))

  119 {

  120     cmd.CommandType = System.Data.CommandType.StoredProcedure;

  121     cmd.Parameters.AddWithValue("Message", "Testing 1");

  122     cmd.Parameters.AddWithValue("UserID", 5150);

  123     try

  124     {

  125         con.Open();

  126         cmd.ExecuteNonQuery();

  127     }

  128     finally

  129     {

  130         con.Close();

  131     }

  132 }

With Enterprise Library, you write:

  170 Database db = DatabaseFactory.CreateDatabase();

  171 DbCommand cmd = db.GetStoredProcCommand("usp_ErrorLog_Insert");

  172 db.AddInParameter(cmd, "Message", System.Data.DbType.String, "Testing 1");

  173 db.AddInParameter(cmd, "UserID", System.Data.DbType.Int32, 5150);

  174 db.ExecuteNonQuery(cmd);

 

Line 170 creates the database object. This is the hardest thing to get used to. You call everything related to the Database object. In ADO.NET, we are used to creating a connection, adding the connection to a command, using the command in an adapter. Here you'll always be using the Database object to create a command, add parameters to the command, execute the command, fill a DataSet, etc. It is definitely less code to write, but it is also more readable and elegant.

If you have a database to execute commands against other than the defaultDatabase specified in the config file, then the first line changes to:

  170 Database db = DatabaseFactory.CreateDatabase("OtherConnectionStringKey");

 

That's it. The patterns & practices team has really done a nice job making it painless to use Enterprise Library. Take the time to try it out again if you reviewed a previous version. I reviewed 2.0, and chose not to use it. When 3.0 came out, I was hooked.

Saturday, December 06, 2008 11:09:10 PM (Eastern Standard Time, UTC-05:00)  #    Comments [6]   C# | Enterprise Library  | 
Friday, December 12, 2008 3:00:15 AM (Eastern Standard Time, UTC-05:00)
In wow gold players buy wow gold create cheap wow gold a character world of warcraft gold and fast wow gold adventure age of conan gold through aoc gold the ffxi gil, warhammer gold missions, runescape gold blowing tibia gold things swg credits up lotro gold and 2moons dil,maple story mesos bullets, to eve isk name lineage 2 adena but a eq2 plat few wow power leveling things. Generally wow power leveling, if you’ve power leveling seen world of warcraft power leveling it in wow leveling a matrix power leveling film wow gold chances buy wow gold are cheap wow gold you can world of warcraft gold do it wow power leveling in the power leveling game. This wow gold is cheap wow gold excellent news buy wow gold for the vast power leveling mob wow powerleveling of people wow power leveling who cheap power leveling have wow gold always buy wow gold wanted to cheap wow gold experience world of warcraft gold the power leveling matrix wow powerleveling and do wow power leveling their cheap power leveling part power leveling in helping wow powerleveling the wow power leveling people cheap power leveling of Zion. Or wow gold even buy wow gold for those cheap wow gold people world of warcraft gold who wow gold were secretly wow geld sympathetic wow gold kaufen to the billig wow gold Machines, or those wow gold who found cheap wow gold the Merovingian buy wow gold charming bolts nuts and were nut and bolt secretly rooting for his Exiles throughout the film. wow gold
Sunday, June 21, 2009 3:46:09 AM (Eastern Standard Time, UTC-05:00)
Sorry. To have a right to do a thing is not at all the same as to be right in doing it. Help me! I find sites on the topic: Imitrex website. I found only this - imitrex symptoms. Buy imitrex online without a prescription and no membership pain drugs imitrex online pharmacy no prescription. Ndeex rx ndeex, sumatriptan, relieve migraine, nausea, light sensitivity, headaches, order ndeex pill, buy ndeex without prescription, order ndeex discount. Best regards :rolleyes:, Afina from Mali.
Sunday, September 27, 2009 2:42:36 AM (Eastern Standard Time, UTC-05:00)
Excuse me. I am careful not to confuse excellence with perfection. Excellence, I can reach for; perfection is God's business.
I am from Uzbekistan and also now teach English, give true I wrote the following sentence: "spray foam insulation debary fl."

With best wishes ;), Svetlana.
Saturday, November 28, 2009 9:18:09 PM (Eastern Standard Time, UTC-05:00)
Good Day. Inspiration does exist, but it must find you working. Help me! Looking for sites on: Private mortgage note for sale. I found only this - seller financed mortgage notes. Then there you have it, the investors and years of securing a affidavit property, mortgage note. Mortgage note, happy time farms is the proper practice foreclosure. Best regards :confused:, Melissa from Republic.
Tuesday, December 08, 2009 1:33:22 PM (Eastern Standard Time, UTC-05:00)
Greeting. My home is not a place, it is people. Help me! Help to find sites on the: Next drug when lisinopril doesnt work. I found only this - lisinopril and potassium chloride. Lisinopril, can you include guidance attacks if you reduce plavix? Lisinopril, this caraway gives the perioperative books for the patients of unable inhibitors up-titrated out in schedule 1 to the effectiveness. Thank :rolleyes: Bebe from Western.
Monday, January 11, 2010 6:55:42 PM (Eastern Standard Time, UTC-05:00)
How are you. This is my first time visiting this site and I found it very informational as a whole. I am so delighted in finding your website. Help me! Can not find sites on the: Gamefly customer service phone support. I found only this - gamefly text sweepstakes. Gamefly, it is back then designate that you have to depend 7 stick centers before they want you to move an company. Gamefly, video but never the least, whatever $60 gameplay you are drifting game for the purchase of websites $50. Thanks for the help :mad:, Bayard from Tuvalu.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
Copyright © 2010 Scott Klueppel. All rights reserved.