Comparison of SQL Server.net and OLE DB.NET Connection Database

xiaoxiao2021-03-06  15

ADO.NET database access is conducted by the software module known as "Data Provider" ..NET Framework 1.0 version is "Split Person", it is to provide two data providers: SQL Server.NET Provider and OLE DB.NET Provider.

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

OLE DB.NET Provider It is an interface to access the database via the OLE DB provider.

The following is a brief introduction to the difference between them on the connection database:

The following example lists all the book names included in the Titles table included in the Pubs database with the SQL Server.net provider program:

Using system.data.sqlclclient; ... SqlConnection conn = new SqlConnection ("Server = localhost; uid = sa; pwd =; dataBase = PUBS"); try {conn = conn.open (); sqlcommand command = new SqlCommand (" Select * from titles ", conn; sqldatarader reader = command.executeRead (); while (Reader.Read ()) {console.writeline (Reader [" title "]);}} catch (sqlexception e) {Console.writeline (e.tostring ());} finally {conn.close ();

The following uses the OLE DB.NET provider program to rewrite:

Using system.data.oledb; ... oledbconnection conn = new oledbconnection ("provider = sqloledb; server = localhost; uid = sa; pwd =; dataBase = PUBS");

Try {conn = conn (); oledbcommand command = new oledbcommand ("select * from titles", conn; oledbdatareader reader = command.executeReader (); while (reader.read ()) {console.writeline (Reader [ "Title"]);}}} catches (OLEDBEXCEPTION E) {Console.writeLine (E.TOString ());} finally {conn.close ();

转载请注明原文地址:https://www.9cbs.com/read-45715.html

New Post(0)