Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I am using asp.net and currently working with SQL SERVER 2008.
In my code all the DML operation is happening with the help of
SqlConnection, SqlCommand, SqlDataAdapter.

But when If my database move to ORACLE or MySQL then I would need to write the code for
ORACLE -- OLEDBConnection, OLEDBCommand, OLEDBDataAdapter
MySQL -- Would need to include a MySQL dll.

Now due to this huge change I would need to write the entire code again.

Is there any way to overcome this problem that we write the code at once and that would not depend on the database provider?
Does the Entity Framework come in this picture anywhere?

Please guide me.

Thanks
Posted

1 solution

Actually you can use OleDb for most of the databases. You just have to make sure that you have proper OleDb provider downloaded. For example Oracle OleDb provider can be loaded from Oracle site, for MySql you can use OleDb for ODBC and MySql ODBC driver if no suitable OleDb provider is found for that (the only ones I know are commercial) and so forth.

However there are few things you must remember:
- when working with OleDb with multiple databases you cannot use database specific features for .Net objects (ones that exist for example for SqlCOnnection or OracleConnection)
- The SQL syntax is still different. For each database you may have to create alternative versions for all statements.

You could of course create small wrapper classes to hide the actual connection, command etc objects but still you have differences in SQL syntax between the databases.

EF can be used to make your code more compatible with all the databases. However there still may be situations where you have to write SQL and/or the behaviour is different between databases.
 
Share this answer
 
v2
Comments
Espen Harlinn 30-Dec-12 8:13am    
Nice reply :-D
Wendelius 4-Jan-13 15:12pm    
Thanks Espen :-D
Manish Kumar Namdev 7-Jan-13 0:15am    
Thanks Mika Wendelius for reply...
Please guide me a bit more in the context of E.F.
Are both the Entity Framework and Ado .net Entity Frame same or different?
There are four approaches 1. Database First 2. Model First 3. Code First 4. Code First with Existing database.

The working style with E.F. and LINQ TO SQL is smilimar.

Please correct me if I'm at wrong somewhere.

Thanks
Wendelius 10-Jan-13 2:31am    
Entity framework is ADO.Net based so it's the same thing. The approach to be used is based on your way to work, do you first create the database and then the code etc.

The working style is quite similar. However, EF has lots of more capabilities for example regarding to navigation using foreign keys etc.

So basically yes, you're quite correct :)
Manish Kumar Namdev 11-Jan-13 1:36am    
Thanks Mika.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900