<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:georss="http://www.georss.org/georss" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Scott Klueppel's Blog - Enterprise Library</title>
    <link>http://offroadcoder.com/</link>
    <description>making the hard line look easy</description>
    <language>en-us</language>
    <copyright>Scott Klueppel</copyright>
    <lastBuildDate>Tue, 27 Jul 2010 03:32:07 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8102.813</generator>
    <managingEditor>me@offroadcoder.com</managingEditor>
    <webMaster>me@offroadcoder.com</webMaster>
    <item>
      <trackback:ping>http://offroadcoder.com/Trackback.aspx?guid=fb59ebf8-4230-43f8-9226-b02389165fc1</trackback:ping>
      <pingback:server>http://offroadcoder.com/pingback.aspx</pingback:server>
      <pingback:target>http://offroadcoder.com/PermaLink,guid,fb59ebf8-4230-43f8-9226-b02389165fc1.aspx</pingback:target>
      <dc:creator>Scott Klueppel</dc:creator>
      <georss:point>30.109017 -81.497099</georss:point>
      <wfw:comment>http://offroadcoder.com/CommentView,guid,fb59ebf8-4230-43f8-9226-b02389165fc1.aspx</wfw:comment>
      <wfw:commentRss>http://offroadcoder.com/SyndicationService.asmx/GetEntryCommentsRss?guid=fb59ebf8-4230-43f8-9226-b02389165fc1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In .NET 1.1, I tried the original MS Data Access Application Block’s SqlHelper (you
can still download it <a href="http://download.microsoft.com/download/VisualStudioNET/daabref/RTM/NT5/EN-US/DataAccessApplicationBlock.msi">here</a>).
It was great for most of the common uses, but was lacking in some areas. The consuming
code looked sloppy and encouraged blind faith that database objects never changed.
It also didn’t support transactions as I would have liked, and didn’t support my obsession
with custom entities. I started out writing an extension library that wrapped SqlHelper,
but that felt very wrong… wrapping the ADO.NET wrapper (SqlHelper). I ended up writing
my own version of SqlHelper called SqlHelper (nice name, eh?). You see, at this time
I was getting over a bad relationship with a series of ORM products that had a negative
effect on my productivity. I decided to revolt with good ol’ fashion data access methods
that have never let us down.
</p>
        <p>
The only thing worse than my ORM experience was the disgusting over-use of DataSet
and DataTable. For my dollar, DataReader is where it’s at. I agree that using the
reader is slightly more dangerous in the hands of an inexperienced or inattentive
developer (did you know you have to close the reader when you’re done with it??).
Nothing can compare with the speed and flexibility of the reader, which is why DataSet
and DataAdapter use it at their core. If you are working with custom entities, instead
of DataSets and DataTables, you would be crazy to not use the DataReader.
</p>
        <p>
My SqlHelper worked in conjunction with my DataAccessLayer class that defined a few
delegates that made reader-to-object-mapping a simple task.  Once the mapping
methods were written to be used with the delegates, which returned object or System.Collections.CollectionBase
because we did not yet have generics (can you imagine??), you simply called the SqlHelper
to do all of the hard work. SqlHelper did not implement all of the craziness that
the original version contained. It was a short 450 lines of code that did nothing
but access data in a safe and reliable way. In the example below, we have the GenerateDocumentFromReader
method that is used by the GenerateObjectFromReader delegate. When SqlHelper.ExecuteReaderCmd
is called, the delegate is passed in to map the reader results to my object… in this
case a Document.
</p>
        <pre class="brush: c#;">// Object generation method 
private static object GenerateDocumentFromReader(IDataReader returnData) 
{
     Document document = new Document();
     if (returnData.Read())
     {
         document = new Document(
             (int)returnData["DocumentId"],
             (byte[])returnData["DocumentBinary"],
             returnData["FileName"].ToString(),
             returnData["Description"].ToString(),
             returnData["ContentType"].ToString(),
             (int)returnData["FileSize"],
             returnData["MD5Sum"].ToString(),
             (bool) returnData["EnabledInd"],
             (int)returnData["CreatorEmpId"],
             Convert.ToDateTime(returnData["CreateDt"]),
             (int)returnData["LastUpdateEmpId"],
             Convert.ToDateTime(returnData["LastUpdateDt"]));
     }     return document;
} 
public static Document GetDocumentByDocumentId(int documentId)
{
     SqlCommand sqlCmd = new SqlCommand();
     SqlHelper.SetCommandArguments(sqlCmd, CommandType.StoredProcedure, "usp_Document_GetDocumentByDocumentId");
     SqlHelper.AddParameterToSqlCommand(sqlCmd, "@DocumentId", SqlDbType.Int, 0, ParameterDirection.Input, documentId);
     DataAccessLayer.GenerateObjectFromReader gofr = new DataAccessLayer.GenerateObjectFromReader(GenerateDocumentFromReader);
     Document document = SqlHelper.ExecuteReaderCmd(sqlCmd, gofr) as Document;
     return document;
}
</pre>
        <p>
This worked wonderfully for years. After converting, I couldn’t imagine a project
that used ORM, DataSets, or DataTables again. I’ve been on many 1.1 projects since
writing my SqlHelper in 2004, and I have successfully converted them all. In early
2006, MS graced us with .NET 2.0. Generics, System.Transactions, and partial classes
changed my life. In my first few exposures to generics, like Vinay “the Generic Guy”
Ahuja’s 2005 Jax Code Camp presentation and Juval “My Hero” Lowy’s <a href="http://msdn.microsoft.com/en-us/library/ms379564">MSDN
article “An Introduction to Generics”</a>, I listened/read and pondered the millions
of uses of generics. I adapted my SqlHelper heavily to use these new technologies
and morphed it into something else that closely represented the newest version of
the DAAB, Enterprise Library 3.
</p>
        <p>
By this point, I wanted to convert to Enterprise Library. It was far better than the
simple SqlHelper. It had better transaction support, though I don’t know if that included
System.Transactions. I could have put my object generation extensions on top of it
and it would have worked well for years. On home projects I had already converted
to use EntLib. At work I was not so lucky. The deep stack trace when something went
wrong scared everyone, and that is still a fear for those starting out in EntLib today.
To ease the fears, I just created my replacement to SqlHelper… the Database class. 
</p>
        <p>
I used a lot of the same naming conventions as Enterprise Library. In fact, much of
the consuming code was nearly identical (except for the fact that it did not implement
the provider pattern and worked only with SQL Server). This was in anticipation of
a quick adoption of Enterprise Library 3 in the workplace. Kind of a “see… not so
bad” move on my part. Just like EntLib, you created a Database class using the DatabaseFactory
that used your default connection string key. Commands and parameters were created
and added with methods off of the Database class. Aside from the SqlCommand/DbCommand,
everything looked and felt the same, but came in a small file with only 490 lines
of code instead of 5 or more projects with 490 files. Using it felt the same, too.
Only my object/collection generation extensions looked different from the standard
reader, scalar, dataset routines. Below is the same code from above using the Database
class and related classes to create a Document from a reader.
</p>
        <pre class="brush: c#;">// Object generation method
private static Document GenerateDocumentFromReader(IDataReader returnData)
{
     Document document = new Document();
     if (returnData.Read())
     {
         document = new Document(
             GetIntFromReader(returnData, "DocumentId"),
             GetIntFromReader(returnData, "DocumentTypeId"),
             GetStringFromReader(returnData, "DocumentTypeName"),
             GetByteArrayFromReader(returnData, "DocumentBinary"),
             GetStringFromReader(returnData, "FileName"),
             GetStringFromReader(returnData, "Description"),
             GetStringFromReader(returnData, "ContentType"),
             GetIntFromReader(returnData, "FileSize"),
             GetStringFromReader(returnData, "MD5Sum"),
             GetStringFromReader(returnData, "CreatorEmpID"),
             GetDateTimeFromReader(returnData, "CreateDt"),
             GetStringFromReader(returnData, "LastUpdateEmpID"),
             GetDateTimeFromReader(returnData, "LastUpdateDt"));
     }
     return document;
} 
public static Document GetDocumentByDocumentId(int documentId)
{
     Database db = DatabaseFactory.CreateDatabase(AppSettings.ConnectionStringKey);
     SqlCommand sqlCmd = db.GetStoredProcCommand("usp_Document_GetDocumentByDocumentId");
     db.AddInParameter(sqlCmd, "DocumentId", SqlDbType.Int, documentId);
     GenerateObjectFromReader&lt;Document&gt; gofr = new GenerateObjectFromReader&lt;Document&gt;(GenerateDocumentFromReader);
     Document document = CreateObjectFromDatabase&lt;Document&gt;(db, sqlCmd, gofr);
     return document;
}
</pre>
        <p>
This, too, worked great for years. Other than a brief period in 2007 when I tried
to wrap all of my data access code with WCF services, .NET 3.0 came and went with
no changes to my data access methodology. In late 2007, I had lost all love of my
SqlHelper and my Database/DataAccessLayer classes. With .NET 3.5 and Enterprise Library
4.0, I no longer felt the need to roll my own. .NET now had extension methods for
me to extend Enterprise Library however I pleased. Enterprise Library supported System.Transactions
making its use a dream if behind a WCF service that allowed transaction flow. With
a succinct 190 lines of extension code, I had it made in the shade with Enterprise
Library 4.0. In fact, I haven’t used anything since.
</p>
        <p>
The consuming code was almost exactly the same. You’ll notice the SqlCommand has changed
to DbCommand. The SqlDbType has changed to DbType. Other than that, it feels and works
the same. 
</p>
        <pre class="brush: c#;">// Object generation method
private static Document GenerateDocumentFromReader(IDataReader returnData)
{
     Document document = new Document();
     if (returnData.Read())
     {
         document = new Document(
             returnData.GetInt32("DocumentId"),
             returnData.GetInt32("DocumentTypeId"),
             returnData.GetString("DocumentTypeName"),
             returnData.GetByteArray("DocumentBinary"),
             returnData.GetString("FileName"),
             returnData.GetString("Description"),
             returnData.GetString("ContentType"),
             returnData.GetInt32("FileSize"),
             returnData.GetString("MD5Sum"),
             returnData.GetString("CreatorEmpID"),
             returnData.GetDateTime("CreateDt"),
             returnData.GetString("LastUpdateEmpID"),
             returnData.GetDateTime("LastUpdateDt"));
     }
     return document;
}
public static Document GetDocumentByDocumentID(int documentId)
{
     Database db = DatabaseFactory.CreateDatabase();
     DbCommand cmd = db.GetStoredProcCommand("usp_Document_GetDocumentByDocumentId");
     db.AddInParameter(cmd, "DocumentID", DbType.Int32, documentId);
     GenerateObjectFromReader&lt;Document&gt; gofr = new GenerateObjectFromReader&lt;Document&gt;(GenerateDocumentFromReader);
     Document document = db.CreateObject&lt;Document&gt;(cmd, gofr);
     return document;
}
</pre>
        <p>
With a full suite of unit test projects available for download with the Enterprise
Library source files, the fear should be abated for the remaining holdouts. Getting
started is as easy as including two DLL references, and adding 5 lines of config.
You can’t beat that!
</p>
        <p>
I downloaded Enterprise Library 5 last week. I’ve been making use of new features
such as result set mapping (eliminating the need for my object generation extensions),
parameter mapping, and accessors that bring them all together. There’s a bunch of
inversion of control features in place as well. I think I’ll be quite comfortable
in my new EntLib5 home.
</p>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=fb59ebf8-4230-43f8-9226-b02389165fc1" />
      </body>
      <title>My data access story before Enterprise Library 5</title>
      <guid isPermaLink="false">http://offroadcoder.com/PermaLink,guid,fb59ebf8-4230-43f8-9226-b02389165fc1.aspx</guid>
      <link>http://offroadcoder.com/2010/07/27/MyDataAccessStoryBeforeEnterpriseLibrary5.aspx</link>
      <pubDate>Tue, 27 Jul 2010 03:32:07 GMT</pubDate>
      <description>&lt;p&gt;
In .NET 1.1, I tried the original MS Data Access Application Block’s SqlHelper (you
can still download it &lt;a href="http://download.microsoft.com/download/VisualStudioNET/daabref/RTM/NT5/EN-US/DataAccessApplicationBlock.msi"&gt;here&lt;/a&gt;).
It was great for most of the common uses, but was lacking in some areas. The consuming
code looked sloppy and encouraged blind faith that database objects never changed.
It also didn’t support transactions as I would have liked, and didn’t support my obsession
with custom entities. I started out writing an extension library that wrapped SqlHelper,
but that felt very wrong… wrapping the ADO.NET wrapper (SqlHelper). I ended up writing
my own version of SqlHelper called SqlHelper (nice name, eh?). You see, at this time
I was getting over a bad relationship with a series of ORM products that had a negative
effect on my productivity. I decided to revolt with good ol’ fashion data access methods
that have never let us down.
&lt;/p&gt;
&lt;p&gt;
The only thing worse than my ORM experience was the disgusting over-use of DataSet
and DataTable. For my dollar, DataReader is where it’s at. I agree that using the
reader is slightly more dangerous in the hands of an inexperienced or inattentive
developer (did you know you have to close the reader when you’re done with it??).
Nothing can compare with the speed and flexibility of the reader, which is why DataSet
and DataAdapter use it at their core. If you are working with custom entities, instead
of DataSets and DataTables, you would be crazy to not use the DataReader.
&lt;/p&gt;
&lt;p&gt;
My SqlHelper worked in conjunction with my DataAccessLayer class that defined a few
delegates that made reader-to-object-mapping a simple task.&amp;nbsp; Once the mapping
methods were written to be used with the delegates, which returned object or System.Collections.CollectionBase
because we did not yet have generics (can you imagine??), you simply called the SqlHelper
to do all of the hard work. SqlHelper did not implement all of the craziness that
the original version contained. It was a short 450 lines of code that did nothing
but access data in a safe and reliable way. In the example below, we have the GenerateDocumentFromReader
method that is used by the GenerateObjectFromReader delegate. When SqlHelper.ExecuteReaderCmd
is called, the delegate is passed in to map the reader results to my object… in this
case a Document.
&lt;/p&gt;
&lt;pre class="brush: c#;"&gt;// Object generation method 
private static object GenerateDocumentFromReader(IDataReader returnData) 
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Document document = new Document();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (returnData.Read())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; document = new Document(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (int)returnData["DocumentId"],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (byte[])returnData["DocumentBinary"],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData["FileName"].ToString(),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData["Description"].ToString(),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData["ContentType"].ToString(),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (int)returnData["FileSize"],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData["MD5Sum"].ToString(),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (bool) returnData["EnabledInd"],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (int)returnData["CreatorEmpId"],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Convert.ToDateTime(returnData["CreateDt"]),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (int)returnData["LastUpdateEmpId"],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Convert.ToDateTime(returnData["LastUpdateDt"]));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return document;
} 
public static Document GetDocumentByDocumentId(int documentId)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SqlCommand sqlCmd = new SqlCommand();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SqlHelper.SetCommandArguments(sqlCmd, CommandType.StoredProcedure, "usp_Document_GetDocumentByDocumentId");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SqlHelper.AddParameterToSqlCommand(sqlCmd, "@DocumentId", SqlDbType.Int, 0, ParameterDirection.Input, documentId);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DataAccessLayer.GenerateObjectFromReader gofr = new DataAccessLayer.GenerateObjectFromReader(GenerateDocumentFromReader);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Document document = SqlHelper.ExecuteReaderCmd(sqlCmd, gofr) as Document;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return document;
}
&lt;/pre&gt;
&lt;p&gt;
This worked wonderfully for years. After converting, I couldn’t imagine a project
that used ORM, DataSets, or DataTables again. I’ve been on many 1.1 projects since
writing my SqlHelper in 2004, and I have successfully converted them all. In early
2006, MS graced us with .NET 2.0. Generics, System.Transactions, and partial classes
changed my life. In my first few exposures to generics, like Vinay “the Generic Guy”
Ahuja’s 2005 Jax Code Camp presentation and Juval “My Hero” Lowy’s &lt;a href="http://msdn.microsoft.com/en-us/library/ms379564"&gt;MSDN
article “An Introduction to Generics”&lt;/a&gt;, I listened/read and pondered the millions
of uses of generics. I adapted my SqlHelper heavily to use these new technologies
and morphed it into something else that closely represented the newest version of
the DAAB, Enterprise Library 3.
&lt;/p&gt;
&lt;p&gt;
By this point, I wanted to convert to Enterprise Library. It was far better than the
simple SqlHelper. It had better transaction support, though I don’t know if that included
System.Transactions. I could have put my object generation extensions on top of it
and it would have worked well for years. On home projects I had already converted
to use EntLib. At work I was not so lucky. The deep stack trace when something went
wrong scared everyone, and that is still a fear for those starting out in EntLib today.
To ease the fears, I just created my replacement to SqlHelper… the Database class. 
&lt;/p&gt;
&lt;p&gt;
I used a lot of the same naming conventions as Enterprise Library. In fact, much of
the consuming code was nearly identical (except for the fact that it did not implement
the provider pattern and worked only with SQL Server). This was in anticipation of
a quick adoption of Enterprise Library 3 in the workplace. Kind of a “see… not so
bad” move on my part. Just like EntLib, you created a Database class using the DatabaseFactory
that used your default connection string key. Commands and parameters were created
and added with methods off of the Database class. Aside from the SqlCommand/DbCommand,
everything looked and felt the same, but came in a small file with only 490 lines
of code instead of 5 or more projects with 490 files. Using it felt the same, too.
Only my object/collection generation extensions looked different from the standard
reader, scalar, dataset routines. Below is the same code from above using the Database
class and related classes to create a Document from a reader.
&lt;/p&gt;
&lt;pre class="brush: c#;"&gt;// Object generation method
private static Document GenerateDocumentFromReader(IDataReader returnData)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Document document = new Document();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (returnData.Read())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; document = new Document(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetIntFromReader(returnData, "DocumentId"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetIntFromReader(returnData, "DocumentTypeId"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetStringFromReader(returnData, "DocumentTypeName"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetByteArrayFromReader(returnData, "DocumentBinary"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetStringFromReader(returnData, "FileName"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetStringFromReader(returnData, "Description"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetStringFromReader(returnData, "ContentType"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetIntFromReader(returnData, "FileSize"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetStringFromReader(returnData, "MD5Sum"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetStringFromReader(returnData, "CreatorEmpID"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetDateTimeFromReader(returnData, "CreateDt"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetStringFromReader(returnData, "LastUpdateEmpID"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GetDateTimeFromReader(returnData, "LastUpdateDt"));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return document;
} 
public static Document GetDocumentByDocumentId(int documentId)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Database db = DatabaseFactory.CreateDatabase(AppSettings.ConnectionStringKey);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SqlCommand sqlCmd = db.GetStoredProcCommand("usp_Document_GetDocumentByDocumentId");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; db.AddInParameter(sqlCmd, "DocumentId", SqlDbType.Int, documentId);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GenerateObjectFromReader&amp;lt;Document&amp;gt; gofr = new GenerateObjectFromReader&amp;lt;Document&amp;gt;(GenerateDocumentFromReader);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Document document = CreateObjectFromDatabase&amp;lt;Document&amp;gt;(db, sqlCmd, gofr);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return document;
}
&lt;/pre&gt;
&lt;p&gt;
This, too, worked great for years. Other than a brief period in 2007 when I tried
to wrap all of my data access code with WCF services, .NET 3.0 came and went with
no changes to my data access methodology. In late 2007, I had lost all love of my
SqlHelper and my Database/DataAccessLayer classes. With .NET 3.5 and Enterprise Library
4.0, I no longer felt the need to roll my own. .NET now had extension methods for
me to extend Enterprise Library however I pleased. Enterprise Library supported System.Transactions
making its use a dream if behind a WCF service that allowed transaction flow. With
a succinct 190 lines of extension code, I had it made in the shade with Enterprise
Library 4.0. In fact, I haven’t used anything since.
&lt;/p&gt;
&lt;p&gt;
The consuming code was almost exactly the same. You’ll notice the SqlCommand has changed
to DbCommand. The SqlDbType has changed to DbType. Other than that, it feels and works
the same. 
&lt;/p&gt;
&lt;pre class="brush: c#;"&gt;// Object generation method
private static Document GenerateDocumentFromReader(IDataReader returnData)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Document document = new Document();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (returnData.Read())
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; document = new Document(
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData.GetInt32("DocumentId"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData.GetInt32("DocumentTypeId"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData.GetString("DocumentTypeName"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData.GetByteArray("DocumentBinary"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData.GetString("FileName"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData.GetString("Description"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData.GetString("ContentType"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData.GetInt32("FileSize"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData.GetString("MD5Sum"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData.GetString("CreatorEmpID"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData.GetDateTime("CreateDt"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData.GetString("LastUpdateEmpID"),
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; returnData.GetDateTime("LastUpdateDt"));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return document;
}
public static Document GetDocumentByDocumentID(int documentId)
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Database db = DatabaseFactory.CreateDatabase();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DbCommand cmd = db.GetStoredProcCommand("usp_Document_GetDocumentByDocumentId");
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; db.AddInParameter(cmd, "DocumentID", DbType.Int32, documentId);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GenerateObjectFromReader&amp;lt;Document&amp;gt; gofr = new GenerateObjectFromReader&amp;lt;Document&amp;gt;(GenerateDocumentFromReader);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Document document = db.CreateObject&amp;lt;Document&amp;gt;(cmd, gofr);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return document;
}
&lt;/pre&gt;
&lt;p&gt;
With a full suite of unit test projects available for download with the Enterprise
Library source files, the fear should be abated for the remaining holdouts. Getting
started is as easy as including two DLL references, and adding 5 lines of config.
You can’t beat that!
&lt;/p&gt;
&lt;p&gt;
I downloaded Enterprise Library 5 last week. I’ve been making use of new features
such as result set mapping (eliminating the need for my object generation extensions),
parameter mapping, and accessors that bring them all together. There’s a bunch of
inversion of control features in place as well. I think I’ll be quite comfortable
in my new EntLib5 home.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=fb59ebf8-4230-43f8-9226-b02389165fc1" /&gt;</description>
      <comments>http://offroadcoder.com/CommentView,guid,fb59ebf8-4230-43f8-9226-b02389165fc1.aspx</comments>
      <category>C#</category>
      <category>Database</category>
      <category>Enterprise Library</category>
      <category>Extensions</category>
      <category>SQL</category>
    </item>
    <item>
      <trackback:ping>http://offroadcoder.com/Trackback.aspx?guid=34796dd3-0878-431f-ba53-35e82627bce7</trackback:ping>
      <pingback:server>http://offroadcoder.com/pingback.aspx</pingback:server>
      <pingback:target>http://offroadcoder.com/PermaLink,guid,34796dd3-0878-431f-ba53-35e82627bce7.aspx</pingback:target>
      <dc:creator>Scott Klueppel</dc:creator>
      <georss:point>30.109017 -81.497099</georss:point>
      <wfw:comment>http://offroadcoder.com/CommentView,guid,34796dd3-0878-431f-ba53-35e82627bce7.aspx</wfw:comment>
      <wfw:commentRss>http://offroadcoder.com/SyndicationService.asmx/GetEntryCommentsRss?guid=34796dd3-0878-431f-ba53-35e82627bce7</wfw:commentRss>
      <slash:comments>6</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It's so easy! Start downloading <a href="http://www.microsoft.com/downloads/details.aspx?familyid=1643758B-2986-47F7-B529-3E41584B6CE5&amp;displaylang=en">Enterprise
Library 4.1</a> 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. 
</p>
        <p>
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 &amp; Practices team, or fix it yourself.
</p>
        <p>
The steps to achieve EntLib goodness:
</p>
        <ol>
          <li>
Download Enterprise Library 
</li>
          <li>
Add reference to "Enterprise Library Data Access Application Block" and "Enterprise
Library Shared Library" 
</li>
          <li>
Change your app.config or web.config 
</li>
          <li>
Write some much more readable data access code</li>
        </ol>
        <p>
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 &lt;configSections&gt;
clock and the &lt;dataConfiguration&gt; node. This will allow you to have one default
database for all commands you will execute.
</p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red239\green239\blue143;\red63\green63\blue63;\red227\green198\blue106;\red255\green255\blue255;\red204\green147\blue147;}??\fs18 \cf1\cb2\highlight2 &lt;?\cf3 xml\cf1  \cf4 version\cf1 ="\cf5 1.0\cf1 " \cf4 encoding\cf1 ="\cf5 utf-8\cf1 "?&gt;\par ??&lt;\cf3 configuration\cf1 &gt;\par ??    &lt;\cf3 configSections\cf1 &gt;\par ??        &lt;\cf3 section\cf1  \cf4 name\cf1 ="\cf5 dataConfiguration\cf1 " \cf4 type\cf1 ="\cf5 Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\cf1 " /&gt;\par ??    &lt;/\cf3 configSections\cf1 &gt;\par ??    &lt;\cf3 dataConfiguration\cf1  \cf4 defaultDatabase\cf1 ="\cf5 Testing\cf1 " /&gt;\par ??    &lt;\cf3 connectionStrings\cf1 &gt;\par ??        &lt;\cf3 add\cf1  \cf4 name\cf1 ="\cf5 Testing\cf1 " \cf4 connectionString\cf1 ="\cf5 server=scorpion;database=ApplicationLog;Integrated Security=true;\cf1 "\par ??                  \cf4 providerName\cf1 ="\cf5 System.Data.SqlClient\cf1 " /&gt;\par ??        &lt;\cf3 add\cf1  \cf4 name\cf1 ="\cf5 Testing1\cf1 " \cf4 connectionString\cf1 ="\cf5 server=scorpion;database=ApplicationLog;Integrated Security=true;\cf1 "\par ??                  \cf4 providerName\cf1 ="\cf5 System.Data.SqlClient\cf1 " /&gt;\par ??    &lt;/\cf3 connectionStrings\cf1 &gt;\par ??&lt;/\cf3 configuration\cf1 &gt;}
-->
        </p>
        <p>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red239\green239\blue143;\red63\green63\blue63;\red227\green198\blue106;\red255\green255\blue255;\red204\green147\blue147;}??\fs18 \cf1\cb2\highlight2 &lt;?\cf3 xml\cf1  \cf4 version\cf1 ="\cf5 1.0\cf1 " \cf4 encoding\cf1 ="\cf5 utf-8\cf1 "?&gt;\par ??&lt;\cf3 configuration\cf1 &gt;\par ??    &lt;\cf3 configSections\cf1 &gt;\par ??        &lt;\cf3 section\cf1  \cf4 name\cf1 ="\cf5 dataConfiguration\cf1 " \cf4 type\cf1 ="\cf5 Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\cf1 " /&gt;\par ??    &lt;/\cf3 configSections\cf1 &gt;\par ??    &lt;\cf3 dataConfiguration\cf1  \cf4 defaultDatabase\cf1 ="\cf5 Testing\cf1 " /&gt;\par ??    &lt;\cf3 connectionStrings\cf1 &gt;\par ??        &lt;\cf3 add\cf1  \cf4 name\cf1 ="\cf5 Testing\cf1 " \cf4 connectionString\cf1 ="\cf5 server=scorpion;database=ApplicationLog;Integrated Security=true;\cf1 "\par ??                  \cf4 providerName\cf1 ="\cf5 System.Data.SqlClient\cf1 " /&gt;\par ??        &lt;\cf3 add\cf1  \cf4 name\cf1 ="\cf5 Testing1\cf1 " \cf4 connectionString\cf1 ="\cf5 server=scorpion;database=ApplicationLog;Integrated Security=true;\cf1 "\par ??                  \cf4 providerName\cf1 ="\cf5 System.Data.SqlClient\cf1 " /&gt;\par ??    &lt;/\cf3 connectionStrings\cf1 &gt;\par ??&lt;/\cf3 configuration\cf1 &gt;}
-->
        </p>
        <div style="overflow-y: auto; font-size: 9pt; background: #3f3f3f; width: 865px; color: #dcdccc; font-family: consolas; height: 177px">
          <p style="margin: 0px">
            <span style="color: #efef8f">&lt;?</span>
            <span style="color: #e3c66a">xml</span>
            <span style="color: #efef8f">
            </span>
            <span style="color: white">version</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">1.0</span>
            <span style="color: #efef8f">" </span>
            <span style="color: white">encoding</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">utf-8</span>
            <span style="color: #efef8f">"?&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">&lt;</span>
            <span style="color: #e3c66a">configuration</span>
            <span style="color: #efef8f">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">    &lt;</span>
            <span style="color: #e3c66a">configSections</span>
            <span style="color: #efef8f">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">        &lt;</span>
            <span style="color: #e3c66a">section</span>
            <span style="color: #efef8f">
            </span>
            <span style="color: white">name</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">dataConfiguration</span>
            <span style="color: #efef8f">" </span>
            <span style="color: white">type</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>
            <span style="color: #efef8f">"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">    &lt;/</span>
            <span style="color: #e3c66a">configSections</span>
            <span style="color: #efef8f">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">    &lt;</span>
            <span style="color: #e3c66a">dataConfiguration</span>
            <span style="color: #efef8f">
            </span>
            <span style="color: white">defaultDatabase</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">Testing</span>
            <span style="color: #efef8f">"
/&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">    &lt;</span>
            <span style="color: #e3c66a">connectionStrings</span>
            <span style="color: #efef8f">&gt;</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">        &lt;</span>
            <span style="color: #e3c66a">add</span>
            <span style="color: #efef8f">
            </span>
            <span style="color: white">name</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">Testing</span>
            <span style="color: #efef8f">" </span>
            <span style="color: white">connectionString</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">server=Server_Name;database=DB_Name;Integrated
Security=true;</span>
            <span style="color: #efef8f">"</span>
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">                  </span>
            <span style="color: white">providerName</span>
            <span style="color: #efef8f">="</span>
            <span style="color: #cc9393">System.Data.SqlClient</span>
            <span style="color: #efef8f">"
/&gt;</span>
          </p>
          <p style="margin: 0px">
          </p>
          <p style="margin: 0px">
            <span style="color: #efef8f">
            </span>
          </p>
          <p>
            <span style="color: #efef8f">    &lt;/</span>
            <span style="color: #e3c66a">connectionStrings</span>
            <span style="color: #efef8f">&gt;</span>
            <br />
            <span style="color: #efef8f">&lt;/</span>
            <span style="color: #e3c66a">configuration</span>
            <span style="color: #efef8f">&gt;</span>
          </p>
        </div>
        <p>
 
</p>
        <p>
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.
</p>
        <p>
With ADO.NET, you would write:
</p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b string}\cf3  \cf4 connectionString\cf3  = \cf5 ConfigurationManager\cf3 .\cf4 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf4 ConnectionString\cf3 ;\par ??\cf1 {\b using}\cf3  (\cf5 SqlConnection\cf3  \cf4 con\cf3  = \cf1 {\b new}\cf3  \cf5 SqlConnection\cf3 (\cf4 connectionString\cf3 ))\par ??\cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??\{\par ??    \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??    \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??    \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??    \cf1 {\b try}\par ??\cf3     \{\par ??        \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??        \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??    \}\par ??    \cf1 {\b finally}\par ??\cf3     \{\par ??        \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??    \}\par ??\}}
-->
        </p>
        <div style="overflow-y: auto; font-size: 9pt; background: #3f3f3f; width: 700px; color: #dcdccc; font-family: consolas; height: 248px">
          <p style="margin: 0px">
            <span style="color: #85ac8d">  116</span> <span style="font-weight: bold; color: #e1e18a">string</span><span style="color: #dfdfbf">connectionString</span> = <span style="color: #2b91af">ConfigurationManager</span>.<span style="color: #dfdfbf">ConnectionStrings</span>[<span style="color: #c89191">"Testing"</span>].<span style="color: #dfdfbf">ConnectionString</span>;
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  117</span> <span style="font-weight: bold; color: #e1e18a">using</span> (<span style="color: #2b91af">SqlConnection</span><span style="color: #dfdfbf">con</span> = <span style="font-weight: bold; color: #e1e18a">new</span><span style="color: #2b91af">SqlConnection</span>(<span style="color: #dfdfbf">connectionString</span>))
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  118</span> <span style="font-weight: bold; color: #e1e18a">using</span> (<span style="color: #2b91af">SqlCommand</span><span style="color: #dfdfbf">cmd</span> = <span style="font-weight: bold; color: #e1e18a">new</span><span style="color: #2b91af">SqlCommand</span>(<span style="color: #c89191">"usp_ErrorLog_Insert"</span>, <span style="color: #dfdfbf">con</span>))
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  119</span> {
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  120</span>     <span style="color: #dfdfbf">cmd</span>.<span style="color: #dfdfbf">CommandType</span> = <span style="color: #dfdfbf">System</span>.<span style="color: #dfdfbf">Data</span>.<span style="color: #2b91af">CommandType</span>.<span style="color: #dfdfbf">StoredProcedure</span>;
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  121</span>     <span style="color: #dfdfbf">cmd</span>.<span style="color: #dfdfbf">Parameters</span>.<span style="color: #dfdfbf">AddWithValue</span>(<span style="color: #c89191">"Message"</span>, <span style="color: #c89191">"Testing
1"</span>);
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  122</span>     <span style="color: #dfdfbf">cmd</span>.<span style="color: #dfdfbf">Parameters</span>.<span style="color: #dfdfbf">AddWithValue</span>(<span style="color: #c89191">"UserID"</span>, <span style="color: #8acccf">5150</span>);
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  123</span>     <span style="font-weight: bold; color: #e1e18a">try</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  124</span>     {
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  125</span>         <span style="color: #dfdfbf">con</span>.<span style="color: #dfdfbf">Open</span>();
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  126</span>         <span style="color: #dfdfbf">cmd</span>.<span style="color: #dfdfbf">ExecuteNonQuery</span>();
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  127</span>     }
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  128</span>     <span style="font-weight: bold; color: #e1e18a">finally</span></p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  129</span>     {
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  130</span>         <span style="color: #dfdfbf">con</span>.<span style="color: #dfdfbf">Close</span>();
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  131</span>     }
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  132</span> }
</p>
        </div>
        <p>
        </p>
        <p>
With Enterprise Library, you write:
</p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red43\green145\blue175;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 Database\cf3  \cf4 db\cf3  = \cf1 DatabaseFactory\cf3 .\cf4 CreateDatabase\cf3 (\cf5 "Testing"\cf3 );\par ??\cf1 DbCommand\cf3  \cf4 cmd\cf3  = \cf4 db\cf3 .\cf4 GetStoredProcCommand\cf3 (\cf5 "usp_ErrorLog_Insert"\cf3 );\par ??\cf4 db\cf3 .\cf4 AddInParameter\cf3 (\cf4 cmd\cf3 , \cf5 "Message"\cf3 , \cf4 System\cf3 .\cf4 Data\cf3 .\cf1 DbType\cf3 .\cf4 String\cf3 , \cf5 "Testing 1"\cf3 );\par ??\cf4 db\cf3 .\cf4 AddInParameter\cf3 (\cf4 cmd\cf3 , \cf5 "UserID"\cf3 , \cf4 System\cf3 .\cf4 Data\cf3 .\cf1 DbType\cf3 .\cf4 Int32\cf3 , \cf6 5150\cf3 );\par ??\cf4 db\cf3 .\cf4 ExecuteNonQuery\cf3 (\cf4 cmd\cf3 );}
-->
        </p>
        <div style="overflow-y: auto; font-size: 9pt; background: #3f3f3f; width: 699px; color: #dcdccc; font-family: consolas; height: 82px">
          <p style="margin: 0px">
            <span style="color: #85ac8d">  170</span> <span style="color: #2b91af">Database</span><span style="color: #dfdfbf">db</span> = <span style="color: #2b91af">DatabaseFactory</span>.<span style="color: #dfdfbf">CreateDatabase</span>();
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  171</span> <span style="color: #2b91af">DbCommand</span><span style="color: #dfdfbf">cmd</span> = <span style="color: #dfdfbf">db</span>.<span style="color: #dfdfbf">GetStoredProcCommand</span>(<span style="color: #c89191">"usp_ErrorLog_Insert"</span>);
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  172</span> <span style="color: #dfdfbf">db</span>.<span style="color: #dfdfbf">AddInParameter</span>(<span style="color: #dfdfbf">cmd</span>, <span style="color: #c89191">"Message"</span>, <span style="color: #dfdfbf">System</span>.<span style="color: #dfdfbf">Data</span>.<span style="color: #2b91af">DbType</span>.<span style="color: #dfdfbf">String</span>, <span style="color: #c89191">"Testing
1"</span>);
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  173</span> <span style="color: #dfdfbf">db</span>.<span style="color: #dfdfbf">AddInParameter</span>(<span style="color: #dfdfbf">cmd</span>, <span style="color: #c89191">"UserID"</span>, <span style="color: #dfdfbf">System</span>.<span style="color: #dfdfbf">Data</span>.<span style="color: #2b91af">DbType</span>.<span style="color: #dfdfbf">Int32</span>, <span style="color: #8acccf">5150</span>);
</p>
          <p style="margin: 0px">
            <span style="color: #85ac8d">  174</span> <span style="color: #dfdfbf">db</span>.<span style="color: #dfdfbf">ExecuteNonQuery</span>(<span style="color: #dfdfbf">cmd</span>);
</p>
        </div>
        <p>
 
</p>
        <p>
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.
</p>
        <p>
If you have a database to execute commands against other than the defaultDatabase
specified in the config file, then the first line changes to:
</p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red43\green145\blue175;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red200\green145\blue145;}??\fs18 \cf1\cb2\highlight2 Database\cf3  \cf4 db\cf3  = \cf1 DatabaseFactory\cf3 .\cf4 CreateDatabase\cf3 (\cf5 "Testing"\cf3 );}
-->
        </p>
        <div style="overflow-y: auto; font-size: 9pt; background: #3f3f3f; width: 698px; color: #dcdccc; font-family: consolas; height: 24px">
          <p style="margin: 0px">
            <span style="color: #85ac8d">  170</span> <span style="color: #2b91af">Database</span><span style="color: #dfdfbf">db</span> = <span style="color: #2b91af">DatabaseFactory</span>.<span style="color: #dfdfbf">CreateDatabase</span>(<span style="color: #c89191">"OtherConnectionStringKey"</span>);
</p>
        </div>
        <p>
 
</p>
        <p>
That's it. The patterns &amp; 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.
</p>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=34796dd3-0878-431f-ba53-35e82627bce7" />
      </body>
      <title>How to get started with Enterprise Library Data Application Block</title>
      <guid isPermaLink="false">http://offroadcoder.com/PermaLink,guid,34796dd3-0878-431f-ba53-35e82627bce7.aspx</guid>
      <link>http://offroadcoder.com/2008/12/07/HowToGetStartedWithEnterpriseLibraryDataApplicationBlock.aspx</link>
      <pubDate>Sun, 07 Dec 2008 04:09:10 GMT</pubDate>
      <description>&lt;p&gt;
It's so easy! Start downloading &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=1643758B-2986-47F7-B529-3E41584B6CE5&amp;amp;displaylang=en"&gt;Enterprise
Library 4.1&lt;/a&gt; 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. 
&lt;/p&gt;
&lt;p&gt;
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 &amp;amp; Practices team, or fix it yourself.
&lt;/p&gt;
&lt;p&gt;
The steps to achieve EntLib goodness:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Download Enterprise Library 
&lt;li&gt;
Add reference to "Enterprise Library Data Access Application Block" and "Enterprise
Library Shared Library" 
&lt;li&gt;
Change your app.config or web.config 
&lt;li&gt;
Write some much more readable data access code&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
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 &amp;lt;configSections&amp;gt;
clock and the &amp;lt;dataConfiguration&amp;gt; node. This will allow you to have one default
database for all commands you will execute.
&lt;/p&gt;
&lt;p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red239\green239\blue143;\red63\green63\blue63;\red227\green198\blue106;\red255\green255\blue255;\red204\green147\blue147;}??\fs18 \cf1\cb2\highlight2 &amp;lt;?\cf3 xml\cf1  \cf4 version\cf1 ="\cf5 1.0\cf1 " \cf4 encoding\cf1 ="\cf5 utf-8\cf1 "?&amp;gt;\par ??&amp;lt;\cf3 configuration\cf1 &amp;gt;\par ??    &amp;lt;\cf3 configSections\cf1 &amp;gt;\par ??        &amp;lt;\cf3 section\cf1  \cf4 name\cf1 ="\cf5 dataConfiguration\cf1 " \cf4 type\cf1 ="\cf5 Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\cf1 " /&amp;gt;\par ??    &amp;lt;/\cf3 configSections\cf1 &amp;gt;\par ??    &amp;lt;\cf3 dataConfiguration\cf1  \cf4 defaultDatabase\cf1 ="\cf5 Testing\cf1 " /&amp;gt;\par ??    &amp;lt;\cf3 connectionStrings\cf1 &amp;gt;\par ??        &amp;lt;\cf3 add\cf1  \cf4 name\cf1 ="\cf5 Testing\cf1 " \cf4 connectionString\cf1 ="\cf5 server=scorpion;database=ApplicationLog;Integrated Security=true;\cf1 "\par ??                  \cf4 providerName\cf1 ="\cf5 System.Data.SqlClient\cf1 " /&amp;gt;\par ??        &amp;lt;\cf3 add\cf1  \cf4 name\cf1 ="\cf5 Testing1\cf1 " \cf4 connectionString\cf1 ="\cf5 server=scorpion;database=ApplicationLog;Integrated Security=true;\cf1 "\par ??                  \cf4 providerName\cf1 ="\cf5 System.Data.SqlClient\cf1 " /&amp;gt;\par ??    &amp;lt;/\cf3 connectionStrings\cf1 &amp;gt;\par ??&amp;lt;/\cf3 configuration\cf1 &amp;gt;}
--&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red239\green239\blue143;\red63\green63\blue63;\red227\green198\blue106;\red255\green255\blue255;\red204\green147\blue147;}??\fs18 \cf1\cb2\highlight2 &amp;lt;?\cf3 xml\cf1  \cf4 version\cf1 ="\cf5 1.0\cf1 " \cf4 encoding\cf1 ="\cf5 utf-8\cf1 "?&amp;gt;\par ??&amp;lt;\cf3 configuration\cf1 &amp;gt;\par ??    &amp;lt;\cf3 configSections\cf1 &amp;gt;\par ??        &amp;lt;\cf3 section\cf1  \cf4 name\cf1 ="\cf5 dataConfiguration\cf1 " \cf4 type\cf1 ="\cf5 Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35\cf1 " /&amp;gt;\par ??    &amp;lt;/\cf3 configSections\cf1 &amp;gt;\par ??    &amp;lt;\cf3 dataConfiguration\cf1  \cf4 defaultDatabase\cf1 ="\cf5 Testing\cf1 " /&amp;gt;\par ??    &amp;lt;\cf3 connectionStrings\cf1 &amp;gt;\par ??        &amp;lt;\cf3 add\cf1  \cf4 name\cf1 ="\cf5 Testing\cf1 " \cf4 connectionString\cf1 ="\cf5 server=scorpion;database=ApplicationLog;Integrated Security=true;\cf1 "\par ??                  \cf4 providerName\cf1 ="\cf5 System.Data.SqlClient\cf1 " /&amp;gt;\par ??        &amp;lt;\cf3 add\cf1  \cf4 name\cf1 ="\cf5 Testing1\cf1 " \cf4 connectionString\cf1 ="\cf5 server=scorpion;database=ApplicationLog;Integrated Security=true;\cf1 "\par ??                  \cf4 providerName\cf1 ="\cf5 System.Data.SqlClient\cf1 " /&amp;gt;\par ??    &amp;lt;/\cf3 connectionStrings\cf1 &amp;gt;\par ??&amp;lt;/\cf3 configuration\cf1 &amp;gt;}
--&gt;
&lt;/p&gt;
&lt;div style="overflow-y: auto; font-size: 9pt; background: #3f3f3f; width: 865px; color: #dcdccc; font-family: consolas; height: 177px"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #efef8f"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color: #e3c66a"&gt;xml&lt;/span&gt;&lt;span style="color: #efef8f"&gt; &lt;/span&gt;&lt;span style="color: white"&gt;version&lt;/span&gt;&lt;span style="color: #efef8f"&gt;="&lt;/span&gt;&lt;span style="color: #cc9393"&gt;1.0&lt;/span&gt;&lt;span style="color: #efef8f"&gt;" &lt;/span&gt;&lt;span style="color: white"&gt;encoding&lt;/span&gt;&lt;span style="color: #efef8f"&gt;="&lt;/span&gt;&lt;span style="color: #cc9393"&gt;utf-8&lt;/span&gt;&lt;span style="color: #efef8f"&gt;"?&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #efef8f"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #e3c66a"&gt;configuration&lt;/span&gt;&lt;span style="color: #efef8f"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #efef8f"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #e3c66a"&gt;configSections&lt;/span&gt;&lt;span style="color: #efef8f"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #efef8f"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #e3c66a"&gt;section&lt;/span&gt;&lt;span style="color: #efef8f"&gt; &lt;/span&gt;&lt;span style="color: white"&gt;name&lt;/span&gt;&lt;span style="color: #efef8f"&gt;="&lt;/span&gt;&lt;span style="color: #cc9393"&gt;dataConfiguration&lt;/span&gt;&lt;span style="color: #efef8f"&gt;" &lt;/span&gt;&lt;span style="color: white"&gt;type&lt;/span&gt;&lt;span style="color: #efef8f"&gt;="&lt;/span&gt;&lt;span style="color: #cc9393"&gt;Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;&lt;span style="color: #efef8f"&gt;"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #efef8f"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #e3c66a"&gt;configSections&lt;/span&gt;&lt;span style="color: #efef8f"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #efef8f"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #e3c66a"&gt;dataConfiguration&lt;/span&gt;&lt;span style="color: #efef8f"&gt; &lt;/span&gt;&lt;span style="color: white"&gt;defaultDatabase&lt;/span&gt;&lt;span style="color: #efef8f"&gt;="&lt;/span&gt;&lt;span style="color: #cc9393"&gt;Testing&lt;/span&gt;&lt;span style="color: #efef8f"&gt;"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #efef8f"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #e3c66a"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: #efef8f"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #efef8f"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="color: #e3c66a"&gt;add&lt;/span&gt;&lt;span style="color: #efef8f"&gt; &lt;/span&gt;&lt;span style="color: white"&gt;name&lt;/span&gt;&lt;span style="color: #efef8f"&gt;="&lt;/span&gt;&lt;span style="color: #cc9393"&gt;Testing&lt;/span&gt;&lt;span style="color: #efef8f"&gt;" &lt;/span&gt;&lt;span style="color: white"&gt;connectionString&lt;/span&gt;&lt;span style="color: #efef8f"&gt;="&lt;/span&gt;&lt;span style="color: #cc9393"&gt;server=Server_Name;database=DB_Name;Integrated
Security=true;&lt;/span&gt;&lt;span style="color: #efef8f"&gt;"&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #efef8f"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;span style="color: white"&gt;providerName&lt;/span&gt;&lt;span style="color: #efef8f"&gt;="&lt;/span&gt;&lt;span style="color: #cc9393"&gt;System.Data.SqlClient&lt;/span&gt;&lt;span style="color: #efef8f"&gt;"
/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #efef8f"&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color: #efef8f"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="color: #e3c66a"&gt;connectionStrings&lt;/span&gt;&lt;span style="color: #efef8f"&gt;&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="color: #efef8f"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #e3c66a"&gt;configuration&lt;/span&gt;&lt;span style="color: #efef8f"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
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.
&lt;/p&gt;
&lt;p&gt;
With ADO.NET, you would write:
&lt;/p&gt;
&lt;p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b string}\cf3  \cf4 connectionString\cf3  = \cf5 ConfigurationManager\cf3 .\cf4 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf4 ConnectionString\cf3 ;\par ??\cf1 {\b using}\cf3  (\cf5 SqlConnection\cf3  \cf4 con\cf3  = \cf1 {\b new}\cf3  \cf5 SqlConnection\cf3 (\cf4 connectionString\cf3 ))\par ??\cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??\{\par ??    \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??    \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??    \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??    \cf1 {\b try}\par ??\cf3     \{\par ??        \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??        \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??    \}\par ??    \cf1 {\b finally}\par ??\cf3     \{\par ??        \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??    \}\par ??\}}
--&gt;
&lt;/p&gt;
&lt;div style="overflow-y: auto; font-size: 9pt; background: #3f3f3f; width: 700px; color: #dcdccc; font-family: consolas; height: 248px"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 116&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: #e1e18a"&gt;string&lt;/span&gt; &lt;span style="color: #dfdfbf"&gt;connectionString&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;ConfigurationManager&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;ConnectionStrings&lt;/span&gt;[&lt;span style="color: #c89191"&gt;"Testing"&lt;/span&gt;].&lt;span style="color: #dfdfbf"&gt;ConnectionString&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 117&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: #e1e18a"&gt;using&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;SqlConnection&lt;/span&gt; &lt;span style="color: #dfdfbf"&gt;con&lt;/span&gt; = &lt;span style="font-weight: bold; color: #e1e18a"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SqlConnection&lt;/span&gt;(&lt;span style="color: #dfdfbf"&gt;connectionString&lt;/span&gt;))
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 118&lt;/span&gt;&amp;nbsp;&lt;span style="font-weight: bold; color: #e1e18a"&gt;using&lt;/span&gt; (&lt;span style="color: #2b91af"&gt;SqlCommand&lt;/span&gt; &lt;span style="color: #dfdfbf"&gt;cmd&lt;/span&gt; = &lt;span style="font-weight: bold; color: #e1e18a"&gt;new&lt;/span&gt; &lt;span style="color: #2b91af"&gt;SqlCommand&lt;/span&gt;(&lt;span style="color: #c89191"&gt;"usp_ErrorLog_Insert"&lt;/span&gt;, &lt;span style="color: #dfdfbf"&gt;con&lt;/span&gt;))
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 119&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 120&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;CommandType&lt;/span&gt; = &lt;span style="color: #dfdfbf"&gt;System&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;Data&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;CommandType&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;StoredProcedure&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 121&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;Parameters&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;AddWithValue&lt;/span&gt;(&lt;span style="color: #c89191"&gt;"Message"&lt;/span&gt;, &lt;span style="color: #c89191"&gt;"Testing
1"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 122&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;Parameters&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;AddWithValue&lt;/span&gt;(&lt;span style="color: #c89191"&gt;"UserID"&lt;/span&gt;, &lt;span style="color: #8acccf"&gt;5150&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 123&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="font-weight: bold; color: #e1e18a"&gt;try&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 124&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 125&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #dfdfbf"&gt;con&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;Open&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 126&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;ExecuteNonQuery&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 127&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 128&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="font-weight: bold; color: #e1e18a"&gt;finally&lt;/span&gt;
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 129&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 130&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="color: #dfdfbf"&gt;con&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;Close&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 131&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 132&lt;/span&gt; }
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
With Enterprise Library, you write:
&lt;/p&gt;
&lt;p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red43\green145\blue175;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 Database\cf3  \cf4 db\cf3  = \cf1 DatabaseFactory\cf3 .\cf4 CreateDatabase\cf3 (\cf5 "Testing"\cf3 );\par ??\cf1 DbCommand\cf3  \cf4 cmd\cf3  = \cf4 db\cf3 .\cf4 GetStoredProcCommand\cf3 (\cf5 "usp_ErrorLog_Insert"\cf3 );\par ??\cf4 db\cf3 .\cf4 AddInParameter\cf3 (\cf4 cmd\cf3 , \cf5 "Message"\cf3 , \cf4 System\cf3 .\cf4 Data\cf3 .\cf1 DbType\cf3 .\cf4 String\cf3 , \cf5 "Testing 1"\cf3 );\par ??\cf4 db\cf3 .\cf4 AddInParameter\cf3 (\cf4 cmd\cf3 , \cf5 "UserID"\cf3 , \cf4 System\cf3 .\cf4 Data\cf3 .\cf1 DbType\cf3 .\cf4 Int32\cf3 , \cf6 5150\cf3 );\par ??\cf4 db\cf3 .\cf4 ExecuteNonQuery\cf3 (\cf4 cmd\cf3 );}
--&gt;
&lt;/p&gt;
&lt;div style="overflow-y: auto; font-size: 9pt; background: #3f3f3f; width: 699px; color: #dcdccc; font-family: consolas; height: 82px"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 170&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af"&gt;Database&lt;/span&gt; &lt;span style="color: #dfdfbf"&gt;db&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;DatabaseFactory&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;CreateDatabase&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 171&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af"&gt;DbCommand&lt;/span&gt; &lt;span style="color: #dfdfbf"&gt;cmd&lt;/span&gt; = &lt;span style="color: #dfdfbf"&gt;db&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;GetStoredProcCommand&lt;/span&gt;(&lt;span style="color: #c89191"&gt;"usp_ErrorLog_Insert"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 172&lt;/span&gt;&amp;nbsp;&lt;span style="color: #dfdfbf"&gt;db&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;AddInParameter&lt;/span&gt;(&lt;span style="color: #dfdfbf"&gt;cmd&lt;/span&gt;, &lt;span style="color: #c89191"&gt;"Message"&lt;/span&gt;, &lt;span style="color: #dfdfbf"&gt;System&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;Data&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;DbType&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;String&lt;/span&gt;, &lt;span style="color: #c89191"&gt;"Testing
1"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 173&lt;/span&gt;&amp;nbsp;&lt;span style="color: #dfdfbf"&gt;db&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;AddInParameter&lt;/span&gt;(&lt;span style="color: #dfdfbf"&gt;cmd&lt;/span&gt;, &lt;span style="color: #c89191"&gt;"UserID"&lt;/span&gt;, &lt;span style="color: #dfdfbf"&gt;System&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;Data&lt;/span&gt;.&lt;span style="color: #2b91af"&gt;DbType&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;Int32&lt;/span&gt;, &lt;span style="color: #8acccf"&gt;5150&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 174&lt;/span&gt;&amp;nbsp;&lt;span style="color: #dfdfbf"&gt;db&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;ExecuteNonQuery&lt;/span&gt;(&lt;span style="color: #dfdfbf"&gt;cmd&lt;/span&gt;);
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
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.
&lt;/p&gt;
&lt;p&gt;
If you have a database to execute commands against other than the defaultDatabase
specified in the config file, then the first line changes to:
&lt;/p&gt;
&lt;p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red43\green145\blue175;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red200\green145\blue145;}??\fs18 \cf1\cb2\highlight2 Database\cf3  \cf4 db\cf3  = \cf1 DatabaseFactory\cf3 .\cf4 CreateDatabase\cf3 (\cf5 "Testing"\cf3 );}
--&gt;
&lt;/p&gt;
&lt;div style="overflow-y: auto; font-size: 9pt; background: #3f3f3f; width: 698px; color: #dcdccc; font-family: consolas; height: 24px"&gt;
&lt;p style="margin: 0px"&gt;
&lt;span style="color: #85ac8d"&gt;&amp;nbsp; 170&lt;/span&gt;&amp;nbsp;&lt;span style="color: #2b91af"&gt;Database&lt;/span&gt; &lt;span style="color: #dfdfbf"&gt;db&lt;/span&gt; = &lt;span style="color: #2b91af"&gt;DatabaseFactory&lt;/span&gt;.&lt;span style="color: #dfdfbf"&gt;CreateDatabase&lt;/span&gt;(&lt;span style="color: #c89191"&gt;"OtherConnectionStringKey"&lt;/span&gt;);
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
That's it. The patterns &amp;amp; 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.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=34796dd3-0878-431f-ba53-35e82627bce7" /&gt;</description>
      <comments>http://offroadcoder.com/CommentView,guid,34796dd3-0878-431f-ba53-35e82627bce7.aspx</comments>
      <category>C#</category>
      <category>Enterprise Library</category>
    </item>
  </channel>
</rss>