开发者

What is ADO.NET

I puzzled with understanding ADO.NET, after reading se开发者_StackOverflow中文版veral articles I do not have a clear idea what is perfomance consideration.

  • What is ADO.NET and what about perfomance considerations?
  • ADO.NET could be associated with SQL STORED PROCEDURES or are different things?

Thanks guys!


ADO.NET is a component of the .NET framework that allows you to access different data sources. A stored procedure is different: it is a function that allows you to query a relational database and which runs inside the database.

So you could use ADO.NET to call a stored procedure. Take for example the following:

using (var con = new SqlConnection(SomeConnectionStringToTheDatabase))
using (var cmd = con.CreateCommand())
{
    con.open();
    con.CommandText = "NameOfTheStoredProcdureYouWantToInvoke";
    con.CommandType = CommandType.StoredProcedure;

    var result = command.ExecuteNonQuery();
}

The classes SqlConnection, SqlCommand that we use to call the stored procedure are part of ADO.NET.


Think of Ado.net as a managed library that provides all the classes and functionality you need (and may use) to access external data sources. That's the most simplest way of thinking of it. But since it's not a separate library (because it's included with the .net library) people tend to be confused. We could say it's a library inside .net.

A more thorough explanation can be found on Wikipedia.

Stored procedure is part of a particular data store. Ado.net gives you the ability to call these stored procedures in a standardized way.

An example from MSDN

using (SqlConnection connection = new SqlConnection(connectionString))
{
    // Create the Command and Parameter objects.
    SqlCommand command = new SqlCommand(queryString, connection);
    command.Parameters.AddWithValue("@pricePoint", paramValue);

    // Open the connection in a try/catch block. 
    // Create and execute the DataReader, writing the result
    // set to the console window.
    try
    {
        connection.Open();
        SqlDataReader reader = command.ExecuteReader();
        while (reader.Read())
        {
            Console.WriteLine("\t{0}\t{1}\t{2}", reader[0], reader[1], reader[2]);
        }
        reader.Close();
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
    Console.ReadLine();
}

You can see the use of Ado.net classes:

  • SqlConnection
  • SqlCommand and
  • SqlDataReader

So Ado.net has all these provided for you, so you don't have to reinvent the wheel every time you'd like to access external data sources (relational data bases, services etc.).


ADO.NET is the part of the .NET framework that is the layer between a database driver and your application. All database access in a .NET application goes though ADO.NET.

The database driver is usually a native .NET driver, but it can also be something like an ODBC driver.

Through the ADO.NET routines you can access the database either by using SQL queries, SQL stored procedures, or direct table binding. These are all database specific and varies depending on the database and database driver, however there is a SQL standard that databases expand upon, so there is at least some common ground.

There are data access frameworks that you can use instead of ADO.NET, like the Entity Framework. However they don't replace the ADO.NET, they still use the ADO.NET layer to access the database.


What is ADO.NET?

In general it is a technology to access a database (or other kinds of datasources like a csv file). From the programmers point of view it is just a set of libraries and classes which he needs to get access to a database and its database artifacts (like tables, views or stored procedures).

ADO.NET could be associated with SQL STORED PROCEDURES or are different things?

You use ADO.NET in order to access a stored procedure in a piece of managed code (written in e.g. C# or VB). A stored procedure is a piece of code (written in e.g. PL/SQL or T-SQL), which resides on the database. Yes, they are completely different things.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜