Comparison of SQL server.net and OLE db.net connection databases

Source: Internet
Author: User
Tags comparison microsoft sql server ole tostring
server| Comparison | The database access that connects the database ado.net is carried out through a software module called the data Provider (information provider). NET Framework version 1.0 is "split personality," which he provides two data providers: SQL server.net provider and OLE DB. NET provider.

SQL Server.NET Provider It is an interface to a Microsoft SQL Server database and does not require help from any unmanaged provider.

OLE DB. NET provider It is an interface that accesses a database through an OLE DB provider.

The following is a brief introduction to their differences on the connection database:

The following example lists all the titles in the titles table contained in the pubs database using the SQL Server.NET Provider program:

Using System.Data.SqlClient;
......
SqlConnection conn=new SqlConnection ("server=localhost;uid=sa;pwd=;d atabase=pubs");

Try
{
conn = conn. Open ();
SqlCommand command=new SqlCommand ("SELECT * FROM Titles", Conn);
SqlDataReader Reader=command. ExecuteReader ();
while (reader. Read ())
{
Console.WriteLine (reader["title"]);
}
}
catch (SqlException e)
{
Console.WriteLine (E.tostring ());
}
Finally
{
Conn. Close ();
}


Use OLE DB below. NET Provider program to rewrite:

Using System.Data.OleDb;
......
OleDbConnection conn=new OleDbConnection ("provider=sqloledb;server=localhost;uid=sa;pwd=;d atabase=pubs");

Try
{
conn = conn. Open ();
OleDbCommand command=new OleDbCommand ("SELECT * FROM Titles", Conn);
OleDbDataReader Reader=command. ExecuteReader ();
while (reader. Read ())
{
Console.WriteLine (reader["title"]);
}
}
catch (OleDbException E)
{
Console.WriteLine (E.tostring ());
}
Finally
{
Conn. Close ();
}




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.