Get Started with the Enterprise Library Data Access Application Block
 
Published: 25 Jul 2005
Unedited - Community Contributed
Abstract
If you have downloaded Microsoft's Enterprise Library Data Access Application Block, you may have had difficulty getting started with it. To help you, Bilal Haidar provides a number of simple examples that walk you through the most common uses of this new Application Block.
by Bilal Haidar
Feedback
Average Rating: 
Views (Total / Last 10 Days): 98499/ 87

Introduction

[ Download Code ]

The Enterprise Library Data Access Application Block is the new version of the Microsoft Data Access Application Block (DAAB). Whereas the previous DAAB was a stand-alone application block, the new DAAB is a part of the new Enterprise Library collection of application blocks. You can obtain the most recent version of the library from the Patterns & Practices Enterprise Library Developer Center.

Last week, I spent one whole day trying to figure out how to configure and work with the new Data Access Application Block. This was due to few resources being available on the web. I even visited the Data Access Application Block forum at the ASP.NET Forums, but found few good resources to start with. Even with the few articles I found, I was not immediately successful in learning how to use the different methods available in the new Enterprise Library.

For the above reasons, I decided to write this article; not to explain how to configure the Enterprise Library, but rather to provide sample codes that can be used in a data-driven ASP.NET website.

Outline

In this article, I will start by listing the methods in the Enterprise Library Data Access Application Block (which, from now on, I will refer to as EN-DAAB) that can be used to interact with the database. Then, I will show you how to define the EN-DAAB configuration section in either the App.config or Web.config configuration file. Later, I will present sample code for each method, to show how easy it is to work with those methods. Finally, I will recommend some online websites that you can visit and check the latest news on the EN-DAAB.

Enterprise Library Data Access Methods

The EN-DAAB contains a set of useful methods that can save developers from having to write their own methods for common database functions.

As you may know, the EN-DAAB allows you to interact with different databases including Microsoft SQL Server, Oracle, and IBM DB2. However, when using its methods, you will not notice the difference whether using SQL Server, Oracle, or any other database provider. Everything is encapsulated within those methods, forming a strong abstraction layer that hides from the developer the details of interacting with a particular database. Let us have a look at each method and give a brief explanation of its function.

  1. CreateDatabase(): This method is used to create a new instance of the database being used in the application, called a database object.
  2. ExecuteReader("ReaderName"): This method returns an IDataReader object.
  3. ExecuteDataSet("DataSetName"): This method returns a DataSet object.
  4. LoadDataSet(“DataSetName”): This method fills an existing DataSet object.
  5. ExecuteNonQuery(dbCommandWrapper): This method is used to execute a query that returns a set of fields in a row, and to insert, delete, and update records.
  6. ExecuteScalar(dbCommandWrapper): This method is used only when you want to retrieve a single value from the database.

Define the Configuration

The EN-DAAB requires a configuration file in order to function properly. If you are developing a Windows Forms application, the configuration file is named App.config. On the other hand, if you are developing an ASP.NET web application, the configuration file is named Web.config.

Now the question is how to configure the EN-DAAB? The answer is simple: follow the steps below.

Step1: From the Windows Start menu, navigate to Programs, Microsoft patterns & practices, Enterprise Library, Enterprise Library Configuration. Once you open the Enterprise Library Configuration program, you will see the following window:

Step2: Right-click on the Enterprise Library Configuration node and choose New Application.

Step3: Right-click on the new Application1 node, and select New, Data Access Application block.

You can see in the above figure the Configuration Application Block and the Data Access Application Block. I will first configure the Configuration Block, and then move to the other block.

Step4: Click on the dataConfiguration node and look at the right window. You have the choice of whether to encrypt the configuration section. I will choose not to encrypt the configuration file by setting the value of Encrypt to False.

Step5: Click on the XML File Storage Provider node to specify the filename that will hold the configuration in your application and the XML File Storage Provider. Rename the second field to XmlProvider and leave the first field as it is. Now, click on the Xml Serializer Transformer node, and rename this field to XmlTransformer.

Step6: In this step, I will configure the Data Access Application Block node. This node contains three child nodes:

  1.  Connection Strings
  2. Database Instances
  3.  Database Types

The Connection Strings node is the place where you add the connection string to your database. In this article I will choose to connect to a SQL database. Once you expand the Connection Strings node you will see a default connection string. Click on the Sql Connection String node, and in the right window you have the option of renaming the connection string. To configure the connection string, expand the Sql Connection String node, and you will see that there are three parameters:

  1. Database
  2. Integrated Security
  3. Server

Click on Database parameter, and in the right window write Northwind in the Value field. Then, click on the Server parameter, and in the right window put localhost in the Value field.  Leave all other parameters as they are, although you could have given them names according to your preferences. Note that you can add additional parameters to the connection string by right clicking on Sql Connection String node and adding other parameters.

The other two nodes, Database Instances and Database Types, can be left with their default values.

After you finish all the steps, open File menu item and select Save Application. When you are prompted to choose a file name, choose either the Web.config or the App.config file in your application.

Now that you have seen how to configure the EN-DAAB, let us put the application block into action.

Code Samples

In this section we are going to present a code sample for each of the methods listed above. With these samples you should get a better understanding of how to use these methods while developing your data access methods.

Be sure to add references to the following assemblies:

   Microsoft.Practices.EnterpriseLibrary.Configuration.dll
   Microsoft.Practices.EnterpriseLibrary.Data.dll

You can find these assemblies in the following path:

   [Drive Name]:\Program Files\Microsoft Enterprise Library\bin

In each code file you will need to include the following lines:

   using Microsoft.Practices.EnterpriseLibrary.Configuration;
   using Microsoft.Practices.EnterpriseLibrary.Data;

The database used for the following code samples is the Northwind database that ships with Microsoft SQL Server, and the data table used is the Customers table.

 

Generate a DataReader Object

This code sample shows how to get a DataReader object using the ExecuteDataReader() method.

Below is the stored procedure that returns all records from the Customers table.

Listing 1

CREATE PROCEDURE [dbo].[GetCustomerList]
AS
SET NOCOUNT ON
   SELECT
      *
   FROM 
      [Customers]
GO

The following C# code executes the above stored procedure and obtains the result as a DataReader object:

Listing 2

try
{
   // Create DataBase Instance
   Database db = DatabaseFactory.CreateDatabase();
   // Initialize the Stored Procedure
   DBCommandWrapper dbCommandWrapper = GetStoredProcCommandWrapper("GetCustomerList");
   using (IDataReader dataReader = db.ExecuteReader(dbCommandWrapper))
   { 
      while (dataReader.Read())
      {  
         Response.Write("CustomerID : " +
            dataReader["CustomerID"].ToString()+"<br>");
         Response.Write("CompanyName : " +
         dataReader["CompanyName"].ToString()+"<br><br>");
      }
   }
}
catch (Exception ex)
{
   Response.Write(ex.ToString());
}

As you can see, I start by instantiating a new database object as follows:

    Database db = DatabaseFactory.CreateDatabase();

Then, I define a wrapper object which encapsulates the stored procedure’s name.

   DBCommandWrapper dbCommandWrapper = GetStoredProcCommandWrapper("GetCustomerList");

Finally, using the generated DataReader object, I was able to display the CustomerID and CompanyName values for each record in the Customers table.

using (IDataReader dataReader = db.ExecuteReader(dbCommandWrapper))
   { 
      while (dataReader.Read())
      {

Generate a DataSet Object

This code sample shows how to get a DataSet object using the ExecuteDataSet() method. The same stored procedure used above in Listing 1 is used in this sample code.

Listing 3

try
{
   // Create DataBase Instance
   Database db = DatabaseFactory.CreateDatabase();
   // Initialize the Stored Procedure
   DBCommandWrapper dbCommandWrapper =
   db.GetStoredProcCommandWrapper("GetCustomerList");
   // Generate DataSet object
   DataSet ds = null;
   ds = db.ExecuteDataSet(dbCommandWrapper);
   // Fill DataGrid
   if ( ds.Tables[0].Rows.Count > 0 )
   {   
      // Supposing we have a datagrid whose id is DataGrid1
      DataGrid1.DataSource = ds.Tables[0].DefaultView;
      DataGrid1.DataBind();
   }
   else
      Response.Write("No rows were selected");
}
catch (Exception ex)
{
   Response.Write(ex.ToString());
}

The same initial steps are used in this code sample as in the previous code sample. However, in this sample I am generating a DataSet object, and then using the following code to check whether the DataSet contains any records:

   if ( ds.Tables[0].Rows.Count > 0 )

Based on that check, I choose whether to bind the DefaultView of the DataSet to a DataGrid, or to show a message indicating that no records were returned.

Retrieve a Single Row

To retrieve a single row from a database data table, it is recommended that you use a DataReader object. First of all, a SQL Server stored procedure is shown, then followed by the C# code that will execute the stored procedure and return a DataReader object, holding a single row.

Below is the stored procedure that returns a single record from the Customers table.

Listing 4

CREATE PROCEDURE [dbo].[GetOneCustomer]
(
   @CustomerID NCHAR(5)
)
AS
SET NOCOUNT ON
   SELECT
      *
   FROM
      [Customers]
   WHERE
      [CustomerID] LIKE @CustomerID
GO

The following C# code executes the above stored procedure and obtains a single row in a DataReader object:

Listing 5

try
{
   // Create DataBase Instance
   Database db = DatabaseFactory.CreateDatabase();
   // Initialize the Stored Procedure
   DBCommandWrapper dbCommandWrapper = db.GetStoredProcCommandWrapper("GetOneCustomer");
   dbCommandWrapper.AddInParameter("@CustomerID",DbType.String,"ALFKI");
   using (IDataReader dataReader = db.ExecuteReader(dbCommandWrapper))
   { 
      if (dataReader.Read())
      {
         Response.Write("CustomerID : " + dataReader["CustomerID"].ToString()+"<br>");
         Response.Write("CompanyName : " + dataReader["CompanyName"].ToString()+"<br><br>");
      }
   }
}
catch (Exception ex)
{
   Response.Write(ex.ToString());
}

As you can see in the code above, a new method of the dbCommandWrapper class was used, which is the AddInParameter() method. In the above sample code, this method is used to pass the required @CustomerID parameter to the stored procedure.

The stored procedure in this code sample will query the Customers table and retrieve the row where the CustomerID column matches the CustomerID parameter provided. This explains the need to add an input parameter to the dbCommandWrapper object, as it is a parameter that is required by the stored procedure. In addition to the AddInputParameter() method, there is the AddOutputParameter() method, which I will address in the next section.

Retrieve More than One Column in a Row

The code sample above retrieves an entire record from a database table. Sometimes however we need only specific fields from a row in a database table. In this case we need to supply the stored procedure with not only an input parameter as in the previous section, but also one or more output parameters to store the result of the stored procedure.

The following is an example of a stored procedure which will take as input the CustomerID value and return only two fields: CompanyName and ContactName. For this limited result set, we have to use the AddOutputParameter() method. This method is used to return the output of a stored procedure.

It is recommended when executing a stored procedure with output parameters to use the ExecuteNonQuery() method instead of the ExecuteDataReader() method.

The SQL stored procedure is as follows:

Listing 6

CREATE PROCEDURE [dbo].[GetCustomerMultipleFields]
(
   @CustomerID NCHAR(5),
   @CompanyName NVARCHAR(40) OUTPUT,
   @ContactName NVARCHAR(30) OUTPUT
) 
AS
SET NOCOUNT ON
   SELECT
      @CompanyName = [CompanyName],
      @ContactName = [ContactName]
   FROM
      [Customers]
   WHERE
      [CustomerID] LIKE @CustomerID
GO

The following C# code executes the above stored procedure and uses the AddOutputParameter() method to obtain the results:

Listing 7

try
{
   // Create DataBase Instance
   Database db = DatabaseFactory.CreateDatabase();
   // Initialize the Stored Procedure
   DBCommandWrapper dbCommandWrapper = db.GetStoredProcCommandWrapper("GetCustomerMultipleFields");
   dbCommandWrapper.AddInParameter("@CustomerID", DbType.String, "ALFKI");
   dbCommandWrapper.AddOutParameter("@CompanyName", DbType.String, 40);
   dbCommandWrapper.AddOutParameter("@ContactName", DbType.String, 30);
   //Execute the stored procedure
   db.ExecuteNonQuery(dbCommandWrapper);
   //Display results of the query
   string results = string.Format("Company Name : {0}, Contact Name {1},",
        dbCommandWrapper.GetParameterValue("@CompanyName"),
        dbCommandWrapper.GetParameterValue("@ContactName"));
   Response.Write(results);
}
catch (Exception ex)
{
   Response.Write(ex.ToString());
}

In the above code, I passed a customer ID value to the stored procedure as an input parameter. As the stored procedure is designed to return two values, CompanyName and ContactName, these were identified as output parameters.

To display the returned values we used another method of dbCommandWrapper, which is GetParameterValue(“ParameterName”). This method returns the value of the parameter specified.

Retrieve a Single Field

This is the case where one needs to retrieve a single column of a row inside a database data table. However, if you are just selecting a single column in a row based on a certain primary key, then no need to use output parameters, instead use the ExecuteScalar() method, which will return the single selected column in the stored procedure. The stored procedure used in this section is as follows:

Listing 8

CREATE PROCEDURE [dbo].[GetCustomerSingleColumn]
(
   @CustomerID NCHAR(5)
)
AS
SET NOCOUNT ON
   SELECT 
      [CompanyName] 
   FROM 
      [Customers]
   WHERE 
      [CustomerID] LIKE @CustomerID
GO

The C# code used to execute the above stored procedure is as follows:

Listing 9

try
{
   // Create DataBase Instance
   Database db = DatabaseFactory.CreateDatabase();
   // Initialize the Stored Procedure
   DBCommandWrapper dbCommandWrapper = db.GetStoredProcCommandWrapper("GetCustomerSingleColumn");
   dbCommandWrapper.AddInParameter("@CustomerID", DbType.String, "ALFKI");
   //Execute the stored procedure
   string GetCompanyName = (string) db.ExecuteScalar(dbCommandWrapper);
   //Display results of the query
   string results = string.Format("Company Name : {0}",GetCompanyName);
   Response.Write(results);
}
catch (Exception ex)
{
   Response.Write(ex.ToString());
}

The code is straight forward. I am using ExecuteScalar method to retrieve the returned value, in this case the CompanyName, and then writing the company name to the page.

Insert a New Record

This code sample shows how to insert a new record into the Customers table.

The stored procedure that is used is as follows:

Listing 10

CREATE PROCEDURE InsertRecordIntoCustomer
(
   @CustomerID NCHAR(5),
   @CompanyName VARCHAR(50)
)
AS
DECLARE @Result int
IF EXISTS
(
   SELECT
      NULL
         FROM
      [Customers]
         WHERE
      [CustomerID] LIKE @CustomerID
) 
   BEGIN
      SELECT @Result = -1
      END
ELSE
   BEGIN
      INSERT INTO [Customers]
         (
         [CustomerID],
         [CompanyName]
         )
         VALUES
         (
         @CustomerID,
         @CompanyName
         )
      SELECT @Result = @@ERROR
      END
RETURN @Result
GO

The procedure starts by checking whether the record to insert is already present in the Customers table. If it is found, a value of -1 is returned. If not, the record is inserted and a value of 0 is returned.

The following C# code will execute the above stored procedure. Executing the above stored procedure includes both input and output parameters. Therefore, it is recommended that the ExecuteNonQuery() method is used.

Listing 11

try
{
   // Create DataBase Instance
   Database db = DatabaseFactory.CreateDatabase();
   // Initialize the Stored Procedure
   DBCommandWrapper dbCommandWrapper = db.GetStoredProcCommandWrapper("InsertRecordIntoCustomer");
   // If There are output parameters, use ExecuteNonQuery only, better performance
   dbCommandWrapper.AddInParameter("@CustomerID", DbType.String, "JohnY");
   dbCommandWrapper.AddInParameter("@CompanyName", DbType.String, "Microsoft");
   object Internalvalue = new object();
   dbCommandWrapper.AddParameter("@Result", DbType.Int32, ParameterDirection.ReturnValue,
        "@Result", DataRowVersion.Default,Internalvalue);
   // Get output
   int GetResult = 0;
   // Execute Stored Procedure
   db.ExecuteNonQuery(dbCommandWrapper);
   GetResult = (int)dbCommandWrapper.GetParameterValue("@Result");
   switch ( GetResult )
   {
      case 0:
         Response.Write("Record Inserted.");
         break;
      case -1: 
         Response.Write("Record Already Found.");
         break;
      default:
         Response.Write("Record Not Inserted.");
         break;
   }
}
catch (Exception ex)
{
   Response.Write(ex.ToString());
}

As you can see, the code is very simple. Two input parameters are added to the dbCommandWrapper, representing part of the record to be inserted in the Customers table. A return parameter is also added, representing the result returned by the stored procedure that indicates whether the record was inserted successfully or not. Once again, notice the use of ExecuteNonQuery() method to perform this task.

Update a Record

This code sample shows how to update an existing record in the Customers table.

The stored procedure that is used is as follows:

Listing 12

CREATE PROCEDURE [dbo].[CustomersUpdate]
(
   @CustomerID NCHAR(5),
   @CompanyName NVARCHAR(40)
)
AS
SET NOCOUNT ON
DECLARE @Result INT
IF NOT EXISTS
(
    SELECT   
      NULL
         FROM   
      [Customers]
         WHERE
      [CustomerID] LIKE @CustomerID
) 
   BEGIN
      SELECT @Result = -1
         END
ELSE
   BEGIN
      UPDATE   
         [Customers]  
      SET  
         [CompanyName] = @CompanyName  
      WHERE  
         [CustomerID] = @CustomerID  
      
      SELECT @Result = @@ERROR
   END
RETURN @Result
GO
CREATE PROCEDURE [dbo].[GetCustomerList]
AS
SET NOCOUNT ON
   SELECT
      *
   FROM 
      [Customers]
GO

This stored procedure operates in a manner similar to that shown in the previous code sample. The procedure starts by checking whether the record to be updated already exists. If the record does not exist in the data table a value of -1 is returned. If it exists, the record is updated and a value of 0 is returned.

The following C# code updates a data table record:

Listing 13

try
{
   // Create DataBase Instance
   Database db = DatabaseFactory.CreateDatabase();
   // Initialize the Stored Procedure
   DBCommandWrapper dbCommandWrapper = db.GetStoredProcCommandWrapper("CustomersUpdate");
   // If There are output parameters, use ExecuteNonQuery only, better performance
   dbCommandWrapper.AddInParameter("@CustomerID", DbType.String, "Wessam");
   dbCommandWrapper.AddInParameter("@CompanyName", DbType.String, "TerraVision");
   object Internalvalue = new object();
   dbCommandWrapper.AddParameter("@Result", DbType.Int32, ParameterDirection.ReturnValue, 
        "@Result", DataRowVersion.Default, Internalvalue);
   // Get output
   int GetResult = 0;
   // Execute Stored Procedure
   db.ExecuteNonQuery(dbCommandWrapper);
   GetResult = (int)dbCommandWrapper.GetParameterValue("@Result");
   switch ( GetResult )
   {
      case 0:
         Response.Write("Record Updated.");
         break;
      case -1: 
         Response.Write("Record Not Found.");
         break;
      default:
         Response.Write("Record Not Updated.");
         break;
   }
}
catch (Exception ex)
{
   Response.Write(ex.ToString());
}

The above code is straight forward. Input and output parameters were added to the dbCommandWrapper object. An output parameter is added that represents the result returned by the stored procedure about the status of the update process.  Then a call to execute the stored procedure was issued. If the returned value is zero, this means that the record was inserted successfully and the message “Record Updated” is written to the page. On the other hand, if the returned value is -1, this means that the record to be updated was not found in the data table, and the message “Record Not Found” is written to the page. Any other value of the returned variable means that an unknown error has occurred and the following message is written to the page: “Record Not Updated”.

Delete a Record

The previous code samples showed how to retrieve, insert, and update data in a database. This final code sample shows how to delete a record from a database table.

Following is the stored procedure used to delete a record from the Customers table.

Listing 14

CREATE PROCEDURE [dbo].[CustomersDelete]
(
   @CustomerID NCHAR(5)
)
AS
SET NOCOUNT ON
DECLARE @Result INT
IF NOT EXISTS
(
    SELECT
      NULL
         FROM   
      [Customers]
         WHERE
      [CustomerID] LIKE @CustomerID
)
   BEGIN
      SELECT @Result = -1
         END
ELSE
   BEGIN
      DELETE 
         [Customers]
      WHERE 
         [CustomerID] LIKE @CustomerID
                 
      SELECT @Result = @@ERROR
         END
RETURN @Result
GO

Once again the stored procedure starts by checking whether the record to be deleted actually exists in the database table. If not found, a value of -1 is returned, otherwise the record is deleted and a value of 0 is returned.

The following C# code shows how to run the above stored procedure:

Listing 15

try
{
   // Create DataBase Instance
   Database db = DatabaseFactory.CreateDatabase();
   // Initialize the Stored Procedure
   DBCommandWrapper dbCommandWrapper = db.GetStoredProcCommandWrapper("CustomersDelete");
   // If There are output parameters, use ExecuteNonQuery only, better performance
   dbCommandWrapper.AddInParameter("@CustomerID", DbType.String, "JohnY");
   object Internalvalue = new object();
   dbCommandWrapper.AddParameter("@Result", DbType.Int32, ParameterDirection.ReturnValue, 
        "@Result", DataRowVersion.Default, Internalvalue);
   // Get output
   int GetResult = 0;
   // Execute Stored Procedure
   db.ExecuteNonQuery(dbCommandWrapper);
   GetResult = (int)dbCommandWrapper.GetParameterValue("@Result");
   switch ( GetResult )
   {
      case 0:
         Response.Write("Record Deleted.");
         break;
      case -1: 
         Response.Write("Record Not Found.");
         break;
      default:
         Response.Write("Record Not Deleted.");
         break;
   }
}
catch (Exception ex)
{
   Response.Write(ex.ToString());
}

In the above code, an input parameter is added to the dbCommandWrapper class to be able to execute the stored procedure. A return parameter is also added that represents the result returned by the stored procedure about the status of the delete process. As in the previous code sample, the returned value is checked against three different values. If it has a value of zero, this means the record was deleted successfully, and a message “Record Deleted” is written to the page. If it has a value of -1, this means that the record to be deleted was not found in the database, and a message “Record Not Found” is written to the page. Finally, any other value means that an error occurred when the stored procedure was executing, and a message “Record Not Deleted” is written to the page.

Online Resources

In this section, I will recommend some useful online resources that you should visit often in order to keep track of updates to the EN-DAAB. These resources should also help you understand in depth many issues related to the EN-DAAB.

1.      Microsoft patterns & practices Center

This link is the start page for all things related to Microsoft patterns & practices, of which the Enterprise Library is just one part.  

2.      Enterprise Library

This link is the homepage of the Enterprise Library. The current version of the Enterprise Library consists of seven application blocks, comprising Caching, Configuration, Cryptography, Data Access, Exception Handling, Logging, and Security. Do check this link for new updates to the library.

3.      Scott Densmore

Scott Densmore was one of the founders and developers of the Enterprise Library. Check his Blog for the latest updates and news on the Enterprise Library.

Conclusion

The code download contains a single project named TestEn-DAAB. In addition, you will find the Queries.sql file which contains the code for the stored procedures used in this article. 

Last, but not least, we may summarize the Enterprise Library Data Access Application Block as providing the following features:

  1. Gives access to the most commonly used features of ADO.NET.
  2. Allows writing code that can be used by any database storage medium, with only slight changes required.
  3. Gives the opportunity to secure connection strings by encrypting the configuration settings in the application configuration file.
  4. Simplifies working with stored procedures.

In this article, I provided code samples showing how to use most of the methods of the Enterprise Library Data Access Application Block. In addition, I presented some online links, which I believe are essential to stay up to date with the latest news regarding the Enterprise Library.

Hope you enjoyed my article,

Happy Dot Netting!



User Comments

Title: rt   
Name: rt
Date: 2012-10-23 2:40:03 AM
Comment:
tt
Title: net_beginner   
Name: rgent
Date: 2011-11-05 8:38:21 AM
Comment:
Very helpful and clear article, Thanks!!!
Title: Sr. .NET Developer   
Name: Loften Pierce
Date: 2011-04-26 3:34:21 PM
Comment:
Great article! Very clear and concise!
Title: MELibrary   
Name: shiva
Date: 2011-04-16 4:38:37 AM
Comment:
Excelent Work Brother
Title: source code   
Name: phani
Date: 2011-02-14 12:06:50 AM
Comment:
Hi
Your article is good , But it is not working properly in enterprise library 5.0 , can you prepare an article on enterprise library 5.0 for us like beginners in Enterprise Library 5.0

Thank you,
Phani
Title: source code   
Name: Ahmed
Date: 2011-01-12 12:57:10 PM
Comment:
Hi Bilal,

I tried using your code for testing but I can't open it in VS2008, can you please help?

Thanks
Ahmed
Title: Query!!!   
Name: Dipti
Date: 2010-04-28 3:14:56 AM
Comment:
Hi i am new to Microsoft Enterprise Library, i am using it for My DAL in my application. i am not aware any library of microsoft etrprise is containing DbCommand, DbConnection etc..Can you tell me please which name space do i have to import or i am suppose to use System.Data.Common library..
Thanks!!
Please Answer
(04cp271dipti@gmail.com)
Title: Syntax error.   
Name: Dipal Bhavsar
Date: 2009-12-16 11:50:02 PM
Comment:
Syntax wrong.
Use Microsoft.Practices.EnterpriseLibrary.Data.Configuration;
instead of
using Microsoft.Practices.EnterpriseLibrary.Configuration;
Title: EntLib   
Name: Michael Doug
Date: 2009-07-26 2:30:21 AM
Comment:
Hey is a great article for learning and developing Data Access Application Block.
Title: good   
Name: Abhishek Jha
Date: 2009-07-09 7:49:04 AM
Comment:
Thanks a lot u have solved a great deal of problem i have getting in learning about enterprise library,good going
Title: Enterprise Library Wrapper Class to Implement Run-time Dynamic Connection Strings Without Using Config File   
Name: Raja Lakshman
Date: 2009-06-11 8:25:36 PM
Comment:
Have a look at the above URL (http://www.codeproject.com/KB/dotnet/EntLibWrapper.aspx) to use the DAAB in Enterprise Library with run-time dynamic connection strings.

Hope this helps.

Cheers
Title: SQL Server authentication   
Name: gulfraz
Date: 2009-02-25 8:34:13 AM
Comment:
Hi Bilal!
In my desktop application, I read an xml config file and build the connection string at runtime by using an encrypted password. The connection uses SQL Server authentication. How can I set the connection string at runtime to use sql server authentication with Enterprise Library.


Thank You
Title: Get Started with the Enterprise Library Data Access Application Block   
Name: Mrugesh
Date: 2009-01-06 4:57:54 AM
Comment:
This is very helpful article for dotnet users new with Enterprise Library.
Title: entlib with oracle parameter   
Name: Mahir
Date: 2008-11-12 2:43:58 AM
Comment:
I am facing problem with parameter in oracle. I don't know the exact reasons. The value is not passing to the procedure.
Title: Well done   
Name: Tanweer Hussain
Date: 2008-10-28 6:24:36 PM
Comment:
Even the aricel is based on old Enterprise Library. I felt his article is making life easier,
Title: Re: Raji   
Name: Bilal Haidar
Date: 2008-09-18 3:30:56 PM
Comment:
Well, this article was on an old version of the library.

Check the documentation on the Ent. Lib 4.0, they have good resources!

Regards
Title: No Title   
Name: Raji
Date: 2008-09-18 3:22:26 PM
Comment:
This is very old. For example, DBCommandWrapper no longer works. It is very frustrating to find limited resources about the Enterprise Library, and if you happen to find it, it turns out to be too old and no longer applies to the current version.
Title: Little Candle in The Dark   
Name: Gatot 'Gatz' Wahyudi
Date: 2008-09-02 5:01:23 AM
Comment:
Dear Haidar,

Thank you so much for your helpful article. Like you said before, I didn't find any article that explained this material in more easy way before. Then i found your article. It likes a little candle in the dark. It's enlightening. Thank you.

Best regards,

Gatot Wahyudi
Title: Nice Article   
Name: Anil
Date: 2008-07-07 5:16:46 AM
Comment:
Hi ...


Thanq very much for giving this good article. it helps me a lot...

Regards,
Anil Kumar
Title: ENTLIB   
Name: Vivek Vashisht
Date: 2008-07-01 1:17:06 AM
Comment:
Thanks Bilal.
You have done a nice job over here...
Thanks once again
Title: samples for enterprise library january 2006 version   
Name: Jayanthy
Date: 2008-03-27 6:56:39 AM
Comment:
could you please post some samples for enterprise library january 2006 version , it would be most helpful.The configuration wizard is not the same and so it is difficult to understand.Thank you in advance.
-Jayanthy
Title: Great Article   
Name: Ahmad Shadi
Date: 2008-02-18 11:56:27 AM
Comment:
Thank u very much for this powerfull article
Title: Help please   
Name: Vi
Date: 2008-01-24 9:23:03 AM
Comment:
I like this article. It`s easy to understand.
Thanks ^^

But can u help me..
I`m already install Enterprise Library January 2006, but
why my Enterprise Library Configuration won`t open?

There is an error when I build my Enterprise Library.
Maybe there is something I missed?

thanks a lot
Title: Application Blocks   
Name: Joe
Date: 2008-01-15 10:38:56 AM
Comment:
Thanks
Title: Bad article   
Name: Matt Cameron
Date: 2007-12-10 9:09:04 AM
Comment:
Pointless and Senseless man, I am sorry I wasted my 15 mins on this article because on of my friend sent it to me. I guess you need to update this article or take it off man.

Sorry again, I wouldnt had posted the comment if I would not had wasted time on this.
Title: Application Blocks   
Name: mrudula
Date: 2007-11-05 6:28:54 AM
Comment:
Hi this article is very useful .but i have small doubt.

i am using Enterprise Library 2.0 and 3.0 but i didnt find

Configuration application Block.

please help where i can find this block to encrypt my configuration settings plzzzzzzzzzzz help me

Thanks in advance
Title: Very Good   
Name: RichB
Date: 2007-10-31 3:04:11 PM
Comment:
One of the first articles I've read that actually makes me think that I might actually use this stuff.
Title: You are the MAN!!!!   
Name: Tim
Date: 2007-07-25 3:00:44 PM
Comment:
Thanks for great work!
Title: Great !   
Name: Prakash
Date: 2007-02-05 5:07:13 AM
Comment:
I am a newbie. I found this article excellent but can anyone refer me using Enterprise Library 2.0 using Visual Studio 2005 as concise and comprehensive this is !
Title: Data access block - January 2006   
Name: RVM
Date: 2006-12-08 1:25:33 PM
Comment:
I am using the last version of enterprise library(jan 06).
i need to configure my web file for dataaccess app block but... following these steps, i just see the "data access application block" node.

how can i add the other nodes, i mean, the "configuration application block", "database instances" and "database type" node?

or.. in the last version (jan 06), is this not posible?

thanks a lot
Title: Configuring Oracle Connection   
Name: Faisal
Date: 2006-12-06 2:16:43 AM
Comment:
I need to configure Oracle database connection string using Enterprise Configuration Library tool. Can you give some tips about this. Thanks :)
Title: Need for DAAB uisng Enterprise Library 2.0   
Name: venkatesh
Date: 2006-11-22 2:14:39 AM
Comment:
Its a great Article. But it would be helpful if you could provide the same using the Enterprise library 2.0.
Title: Nice one   
Name: krishna kumar
Date: 2006-08-08 2:02:41 PM
Comment:
hi so useful, simple beauty in presntation, easy for beginers
Title: EL DAAB Command Timeout   
Name: Techno_Dex
Date: 2006-07-27 5:16:28 PM
Comment:
DbCommand dcCommand;
DataSet dsDataSet
string[] saTableNames;

In the new EL DAAB, I have discovered another way to set the Commmand Timeout without modifying the EL code, but I would see the P&P people include Kirk's overloaded methods.

Use this
dcCommand = dDatabase.GetSqlStringCommand(sSQLCommand);
dcCommand.CommandTimeout = 60;
dDatabase.LoadDataSet(dcCommand, dsDataSet , saTableNames);

Instead of this
dDatabase.LoadDataSet(CommandType.Text, sSQLCommand, dsDataSet , saTableNames);
Title: Excellent !!   
Name: Dalton Cernach de Andradde
Date: 2006-07-14 4:12:43 PM
Comment:
Thats great, Its the most compelte introduction to DABB that I've seen.
Title: ELAB   
Name: Harsha
Date: 2006-07-11 1:10:15 PM
Comment:
Good One... Thanks
Title: Re:   
Name: Bilal Hadiar [MVP]
Date: 2006-06-01 2:29:16 AM
Comment:
Hi to all:
Thanks a lot for you all for the great comments you honored me with!

Hope I will always be able to deliver good content to all of you!

Regards
Title: Get Started with the Enterprise Library   
Name: Nikhil
Date: 2006-06-01 2:21:16 AM
Comment:
Very helpful article indeed.Good job.
Title: Using Data Access Block with Oracle   
Name: Hrishi
Date: 2006-05-23 12:54:09 AM
Comment:
Really nice article..

I want to know how to use Ent.Library(DAAB) for Oracle coz lot of online material is for Sql server..If any steps or links are provided for oracle use it would be really nice.
Title: Good one   
Name: Subarno
Date: 2006-04-17 5:32:53 AM
Comment:
Nice. Both concise and comprehensive.
Title: Great Title   
Name: Evangelos Hadjichristodoulou
Date: 2006-04-15 4:59:50 PM
Comment:
Great Job there Bilal
Title: Connection Timeout!!   
Name: Kirk Rose
Date: 2006-04-04 1:00:53 PM
Comment:
I had the same issue and had to write code to extend SQLHelper ExecuteDataset methods. I basically copied one of the overloaded ExecuteDataSet methods, added a timeout parm and then just added a single statement to set the command's timeout...

Hope this helps...

Public Overloads Shared Function ExecuteDataset(ByVal connection As SqlConnection, _
ByVal commandType As CommandType, _
ByVal commandText As String, _
ByVal commandTimeout As Integer, _
ByVal ParamArray commandParameters() As SqlParameter) As DataSet
If (connection Is Nothing) Then Throw New ArgumentNullException("connection")
' Create a command and prepare it for execution
Dim cmd As New SqlCommand
Dim ds As New DataSet
Dim dataAdatpter As SqlDataAdapter
Dim mustCloseConnection As Boolean = False
cmd.CommandTimeout = commandTimeout
PrepareCommand(cmd, connection, CType(Nothing, SqlTransaction), commandType, commandText, commandParameters, mustCloseConnection)
Title: Connection Timeout!!   
Name: dan
Date: 2006-03-06 12:12:47 AM
Comment:
Hi...
DAAB is awesome. But i have one problem using it. Im using DAAB in my application. Im using SQLHelper and its methods(ExecuteDataset to be specific) in Data Access. But my query takes almost 15 minutes to execute. But while executing this query my browser times out after 30 seconds. So after searching i found out that 30 sec is default for any SQL connection and can be changed using command objects timeout property. Since im not using command object can you please tell me how to set timeout using SQLHelper?.
Title: Oracle Connection   
Name: Bilal Haidar
Date: 2006-02-08 7:13:37 AM
Comment:
Hello
You should create a new Profile provider to make it work with Oracle.
This is out of the topic in this article but you can find many such links if you try to do a simple search on google.com

Thanks.
Title: Getting error when connect to oracle   
Name: Toral Gohil
Date: 2006-02-08 7:12:01 AM
Comment:
Hello Bilal Haidar,

I am getting error when i tried to connect to the oracle. I have done all the things that you have stated above. But still it says service not found. Please if you can help me for solving the same. My Id is gohil_toral@yahoo.co.in
Title: Excellent Job!   
Name: Patrick
Date: 2005-12-09 10:40:46 PM
Comment:
Awesome job on this article!
Title: Mr.   
Name: Bilal Haidar [MVP]
Date: 2005-11-04 11:11:39 AM
Comment:
Thank you all for your great comments. I pray to God to be able to present the best for you all the times.

Regarding the "LIKE", I beleive it is better to use "Like" when comparing string or varchars in SQL Server.

Regards
Title: LIKE?   
Name: yourq1
Date: 2005-11-03 8:18:49 PM
Comment:
Haidar,
Why is LIKE used and not equals (=) ?
I understand it's an nchar(5). Ex.:

DELETE
[Customers]
WHERE
[CustomerID] LIKE @CustomerID

That seems to me like an inappropriate generalization?
Please explain! Thanks.
Title: OUTSTANDING   
Name: Sgt13Echo
Date: 2005-11-02 12:28:11 PM
Comment:
This was BY FAR the best tutorial I have seen on application blocks!

I wish more were like this ONE

I GIVE IT A 10

Out!
Title: Ms.   
Name: Preeti
Date: 2005-10-18 10:18:20 AM
Comment:
Hi Bilal,

Excellent code. Very Clear.
I did the intial configuration the way its said here. I keep getting the error like "Parser Error Message: Invalid section name.
The section 'dataConfiguration' does not
exist in the requested configuration file ...."
Could you please help me resolve it?

Actually I am trying to have data access as a seprate class library and then include that dll into my web application.
Title: How to call datareader from another Class   
Name: Tanweer
Date: 2005-09-27 6:12:44 PM
Comment:
I want to access datareader from another class how I can do that.

using (IDataReader dataReader = db.ExecuteReader(dbCommandWrapper))
{
while (dataReader.Read())
Title: Strongly Typed DataSet (to Rosie)   
Name: sloan
Date: 2005-09-07 6:33:54 PM
Comment:
Public Function TitlesDSGet() as MyStronglyTypedDS

dim returnDS as MyStronglyTypedDS = new MyStronglyTypedDS

Dim db As Database = DatabaseFactory.CreateDatabase()

Dim dbCommandWrapper As dbCommandWrapper = db.GetStoredProcCommandWrapper("dbo.uspTitlesGetAll")


db.LoadDataSet(dbCommandWrapper, returnDS, New String() {"Titles", "Publishers"})


Return returnDS

naturally, this example has the strongly typed dataset having 2 tables "Titles" and "Publishers", and the usp will return 2 result sets.

I have only tried that code on Sql Server 2000, fyi.
Title: Re: Richard   
Name: Bilal Haidar [MVP]
Date: 2005-08-25 2:28:10 AM
Comment:
Hi Richard:
I am glad this article was of help to you.
Thanks for the comments on my blog, I did some changes, check them when you have time.

Regards
Title: Very Helpful   
Name: Richard Dudley
Date: 2005-08-24 2:10:02 PM
Comment:
Great job, Bilal! I struggled with this thing for a while, and eventually gave it up for the old DAAB. After I read your article, I figured I'd try the EL one more time, and it's working in my application now. Thanks!
Title: Very good   
Name: Tushar
Date: 2005-08-22 2:05:08 PM
Comment:
Do you have more such examples using other Application Blocks in ASP.NET applications...or do you know of any other links or resources that contains examples using other application blocks...???

Thanks...
Title: strongly type dataset   
Name: Rosie
Date: 2005-08-04 4:51:56 PM
Comment:
Can you use DBCommandWrapper to load a strongly typed dataset. LoadDataSet and ExecuteDataSet does not seem to work
Title: Re: how to use daab in asp.net   
Name: Bilal Haidar [MVP]
Date: 2005-08-04 1:50:47 AM
Comment:
Download the accompanying files from this article, there is a Web application in ASP.NET that tests all the mentioned methods.

Regards
Title: how to use daab in asp.net   
Name: jay
Date: 2005-08-03 10:54:57 PM
Comment:
how can i use daab in asp.net?
Title: Re:   
Name: Bilal Haidar [MVP]
Date: 2005-08-03 9:04:14 AM
Comment:
You can do something like that:

// Build the SQL Query Here
string sqlCmd = "SELET CustomerName FROM Customers WHERE CustomerID=1";
DbCommandWrapper dbCommandWrapper = db.GetStoredProcCommandWrapper(sqlCmd, CustomerID);
string CustomerName = (string)db.ExecuteScalar(dbCommandWrapper);

You can use the GetSqlStringCommandWrapper() too, if you don't have any parameters.

Hope that helps,
Title: Re: Re: UpdateDataSet()   
Name: Dave
Date: 2005-08-03 8:50:04 AM
Comment:
Maybe I'm missing something here. I'm using the latest release of Enterprise Library with Visual Studio 2005 Beta2. I only have two overloads for GetStoredProcCommandWrapper - with and without parameters. There aren't any overloads for GetSqlStringCommandWrapper. I even made sure to open up the source projects and check there.

dave
Title: Re: UpdateDataSet()   
Name: Bilal Haidar MVP
Date: 2005-08-02 4:58:40 PM
Comment:
Hello, check all the overloads of the method GetStoredProcCommandWrapper, it has several overloads one of them you can pass inline query.
If still couldn't find it, ping me again please.

Regards
Title: Oracle SQL statements   
Name: Dave
Date: 2005-08-02 4:40:45 PM
Comment:
I'm working with both MS Sql and Oracle on this project. Most MS DBA's seem to favor stored procedures and most Oracle DBA's seem to favor using inline SQL. I am having a real hard time trying to get the UpdateDataSet method to work with SQL statements instead of stored procedures. Can you show an example of this?

Thanks, dave
Title: Good Job   
Name: Gregg
Date: 2005-07-30 12:40:16 PM
Comment:
Nice. Both concise and comprehensive.
Thank you for taking the time to put this together.
I now have a much clearer understanding than I did before.
Title: Eng.   
Name: Bilal Haidar [MVP]
Date: 2005-07-25 5:05:50 PM
Comment:
I am so happy I was able to make your life easy by providing such an article.
I am glad you liked it,
Thank you for the time you took to read it.

Best of luck,
Regards
Title: Superb   
Name: Rajeev Gopal
Date: 2005-07-25 4:24:42 PM
Comment:
This one is really helpful for the beginners and saves lot of time for them.

Kudos Bilal!
Title: Very Well placed   
Name: Farhan Shaikh
Date: 2005-07-25 12:08:30 PM
Comment:
smooth article and very well written by working with Microsoft Enterprise DAAB Lib. can you put your thought for Exception Handling and Cypto...
Title: Get Started with the Enterprise Library   
Name: Vishal
Date: 2005-07-25 3:19:38 AM
Comment:
It's really helpful article with examples, so that easy to understand as well to implement

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-26 8:02:00 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search