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:
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
:
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.
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.
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).
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.
Connects to SQL Server 2000 and later only, but you will get optimal performance when connecting to those databases.
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.
Connects to legacy databases only, using ODBC drivers. (E.g. MS Access 97.)
Original source
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With