简体   繁体   中英

asp.net: Is sqlConnection ADO?

  • Is sqlConnection ADO, if not, what's the name of the layer?

  • To invoke ADO, (to access non-MS db's), is OleDbConnection the prefered choice?

SqlConnection is part of the ".NET Data Provider for SQL Server" , so it is ADO.NET, not to be confused with the old COM-based ADO.

Also, yes I believe OleDBConnection is preferred for Access. I do not believe there is an out-of-the box native data provider for MS Access.

1) The SqlConnection Class is part of the System.Data.SqlClient namespace, and is considered part of ADO.NET.

2) OleDbConnection is for connecting to OLE databases. If you're talking about building a platform-agnostic data access layer, you should use System.Data.Common.DbProviderFactories to create generic DbConnection, DbCommand, etc, objects as in the following code example:

    Dim objFactory As DbProviderFactory = DbProviderFactories.GetFactory(ConfigurationManager.AppSettings("DbType"))

    Dim objConnection As DbConnection = objFactory.CreateConnection
    objConnection.ConnectionString = strConnectionString

In this example, you'd keep the name of the actual provider you're using in your Application Settings.

Note that the generic DB objects only support lowest-common-denominator methods so if you're looking for something platform-specific, you're out of luck. Also of course you will have to specify a valid DBtype to the provider factory, which means you'll have to use either one of the built in providers (ODBC, MS SQL, Oracle, OLEDB) or a third party one. I think you could get away with ODBC if you have a ODBC driver for your platform, but I don't know much about that one.

For information on the different connection objects included in ADO.NET: MSDN-Connecting to Data Sources

Yes it is part of ADO.NET . If you use SqlConnection , actually it is a part of ADO.NET to make a connection between your application and database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM