Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I be using Odbc, OleDb, SQLClient? What are the trade-offs

I am starting off with a SQLServer database. So it would seem that I should use System.Data.SqlClient namespace. But, there is a chance that we might shut down our SqlServer database and go to MySql or Oracle. For this reason, I am coming up with a set of standards on how our .Net apps will communicate with the database, so as to make it easier to migrate to a different database system in the future if we needed to do so.

So here are the standards:

  1. Use an ORM if possible (eg NHibernate) (No LINQ as it only supports SqlServer, but what about Entity framework and its support for Oracle and MySql?)
  2. If ORM is an over-kill, then use parameterized SQL queries.
  3. Use stored procedures only for long running or complex actions that need to be performed on the database.

Which brings me to my main question at hand. Which namespace should I be using to code my DAL?

It looks to me that the choice is between System.Data.ODBC and System.Data.OleDB:

  • What are the trade-offs?
  • Is one preferred over the other?
  • What are your thoughts about the first 3 standards?
like image 902
Raj Rao Avatar asked Jun 01 '09 22:06

Raj Rao


People also ask

When should we use system data SQLClient and system data OLE DB?

NET applications should always use SqlClient for SQL Server data access. It is also best to use a managed provider for other DBMS products when one is available. OleDbClient or OdbcClient should are intended to be used in . NET apps only when a suitable managed provider is not available.

Should I use OLE DB or ODBC?

OLEDB vs ODBC – Database Support But the OLEDB Provider for ODBC is for ActiveX Data Objects (ADO), as indicated here. So, it will make sense if you are still programming for ADO. It is also the default provider for it. Otherwise, go straight to ODBC if there's no OLEDB provider for your data source.

What is the main difference between OLE DB provider and SQLClient?

OLEDB is much faster than the SQLClient, EXCEPT when it is access through ADO.NET. The drivers for OLEDB are written in native unmanaged code however, when you access these drivers through ADO.NET, you have to go through several layers (including an abstraction layer and a COM interop layer).

Why should I use ODBC?

Using ODBC, an application developer can develop, compile, and ship an application without targeting a specific DBMS. In this scenario, the application developer does not need to use embedded SQL; thereby eliminating the need to recompile the application for each new environment.


4 Answers

System.Data.SQLClient

Connects to SQL Server 2000 and later only, but you will get optimal performance when connecting to those databases.

System.Data.OledbClient

Connects to SQL 6.5

OLEDBClient gives you ability to connect to other database like ORACLE or Access. But for working with SQL Server you will get better performance using SQLClient.

Note: For connecting to ORACLE, Microsoft also has ORACLEClient.

System.Data.ODBCClient

Connects to legacy databases only, using ODBC drivers. (E.g. MS Access 97.)

Original source

like image 184
anshul Avatar answered Oct 28 '22 01:10

anshul


You want to use the SQL Server driver. I understand what you are trying to do but the way you would accomplish supporting multiple databases is by inserting another layer of abstraction. You can do this many ways. But you put the database specific code at the edge of your class hierarchy. Therefore, each class can get the benefits of database specific functionality but the higher level callers don't know or care what database is being used underneath. As far as ORMs, I prefer LLBLGen, but this is just my preference.

Also, just to clarify, LINQ is not specific to SQL Server. That is LINQ-to-SQL. LINQ is a querying technology that you can use in LINQ-to-SQL, LINQ-to-Entities, LINQ-to-objects, and even LLBLGen supports LINQ.

like image 33
BobbyShaftoe Avatar answered Oct 28 '22 01:10

BobbyShaftoe


No matter whether you use SQLClient or Odbc for now, if you use stored procedures or other database-specific features, you'll have to rewrite those if you change database engines.

like image 25
Rob Bratton Avatar answered Oct 28 '22 01:10

Rob Bratton


I'd just use SqlClient and re-write/re-generate the DAL if it changed.

Unless you're going to implement and test on multiple platforms right now, I'm not sure the extra effort right now is a big deal or any less than the effort to redo the DAL, and the fact that you've got a DAL at all means you've got everything in one place for a later change anyway.

like image 44
Cade Roux Avatar answered Oct 28 '22 01:10

Cade Roux