what is Microsoft.Practices.EnterpriseLibrary.Data
Asked Answered
I

1

13

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.

Inclinable answered 19/1, 2013 at 10:45 Comment(3)
I've been where you are so I'm sympathetic. I don't there's there's anything wrong with using the SqlCommand and SqlConnection objects. Things like enterprise library are higher level wrappers that give you the means to write code which can be configured to work with a wider range of databases (more than just SQL Server). If you are just learning, however, I'd say stick with what you've got.Daimon
The Entity Framework is Microsoft's current ORM de jourAmberlyamberoid
@AaronAnodide: I know that there is not anything wrong but i want to know whats the difference and what are the real benefits of 'Microsoft.Practices.EnterpriseLibrary.Data'Inclinable
V
18

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.

Vibration answered 19/1, 2013 at 11:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.