I want to know what Microsoft.Practices.EnterpriseLibrary.Data.dll
is and why we use this assembly.
What are the benefits of this dll?
I want to create a project on 3-tier architecture and am curious on what is the best way for performing sql queries.
Whether I should use this dll or go for simple SqlCommand
and DataAdapter
.
Currently I am working in this way:
(Code in DAL file:)
public void Insert(long id)
{
connection.Open();
SqlCommand dCmd = new SqlCommand("test_procedure", connection);
dCmd.CommandType = CommandType.StoredProcedure;
try
{
dCmd.Parameters.AddWithValue("@id", id);
dCmd.ExecuteNonQuery();
}
catch
{
throw;
}
finally
{
dCmd.Dispose();
connection.Close();
connection.Dispose();
}
}
I am confused whether I am working in a proper way or should if I should better use Microsoft.Practices.EnterpriseLibrary.Data
and work with a DatabaseFactory
.
The main advantage of the Microsoft.Practices.EnterpriseLibrary.Data library is that it makes it easier to produce database-agnostic code. The developer interacts mainly with more generic Database vs SqlConnection and DbCommand vs SqlCommand objects, in theory the mechanism of switching the underlying database, from MSSQL to Oracle becomes somewhat easier. Even though in my development experience I've never seen that occur.
Microsoft.Practices.EnterpriseLibrary.Data also directs the developer to use DbParameter for query parameters, which reduces the risk of SQL injection attacks.
The Microsoft.Practices.EnterpriseLibrary.Data is a higher abstract of the core ADO .Net constructs and enables the developer to complete the same tasks in a minimal amount of code.
If your learning Data access strategies I suggest continuing with ADO .Net the more you understand the basics the more useful Microsoft.Practices.EnterpriseLibrary.Data or Entity Framework or NHibernate is to use because you understand the fundamentals since the technologies are built on top of ADO .Net.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With