更改数据库连接对代码的影响 [英] Change of Database Connection impact on Code

查看:97
本文介绍了更改数据库连接对代码的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用asp.net,目前正在使用SQL SERVER 2008.

在我的代码中,所有DML操作都是在

SqlConnection的帮助下进行的,SqlCommand,SqlDataAdapter。



但是如果我的数据库移动到 ORACLE MySQL 那么我需要编写

的代码 ORACLE - OLEDBConnection,OLEDBCommand,OLEDBDataAdapter

MySQL - 需要包含一个MySQL dll。



现在由于这个巨大的变化,我需要再次编写整个代码。



有没有办法克服这个问题,我们一次编写代码并且不依赖于数据库提供程序?

实体框架是否在任何地方都出现在这个图片中? />


请指导我。



谢谢

解决方案

< blockquote>实际上你可以将OleDb用于大多数数据库。您只需确保已下载适当的OleDb提供程序。例如,Oracle OleDb提供程序可以从Oracle站点加载,对于MySql,如果没有找到合适的OleDb提供程序(我知道的只有商业用途)等等,你可以使用OleDb for ODBC和MySql ODBC驱动程序。



但是你必须记住的事情很少:

- 当使用OleDb和多个数据库时,你无法使用.Net对象的数据库特定功能(那些存在例如SqlCOnnection或OracleConnection)

- SQL语法仍然不同。对于每个数据库,您可能必须为所有语句创建替代版本。



您当然可以创建小包装类来隐藏实际连接,命令等对象但仍然是您数据库之间的SQL语法有所不同。



EF可用于使您的代码与所有数据库更兼容。但是,仍然可能存在必须编写SQL和/或数据库之间的行为不同的情况。


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

解决方案

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.


这篇关于更改数据库连接对代码的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆