如何编写适用于 SqlServer 和 Oracle 的 .Net 应用程序(现在不推荐使用 System.Data.OracleClient)

How to write a .Net application that works with both SqlServer and Oracle (now that System.Data.OracleClient is deprecated)(如何编写适用于 SqlServer 和 Oracle 的 .Net 应用程序(现在不推荐使用 System.Data.OracleClient))
本文介绍了如何编写适用于 SqlServer 和 Oracle 的 .Net 应用程序(现在不推荐使用 System.Data.OracleClient)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

另请参阅 System.Data.OracleClient 命名空间已停用?

(首先不要惊慌,System.Data.OracleClient 还没有被微软删除,但它不在 .net 4 的客户端版本中)

(Firstly don’t panic yet, System.Data.OracleClient is not being removed by Microsoft yet, however it is not in the client version of .net 4)

通过使用 System.Data.OracleClient,可以实现此用途,然而微软决定弃用 OracleClient.(OracleClient 是 Microsoft 为 Oracle 开发的 ADO.NET 提供程序,并作为 .NET Framework 的一部分提供.)

This use to be possible by using System.Data.OracleClient, however Microsoft has decided to deprecate OracleClient. (OracleClient is the ADO.NET provider for Oracle developed by Microsoft and ships as a part of the .NET Framework.)

您可以使用 ODP.Net,但是您是否希望您的 Sql Server 客户必须安装 ODP.Net?(您希望您的任何客户都必须安装 Oracle 软件吗?)

You could use ODP.Net, however do you wish your Sql Server customers to have to install ODP.Net? (Do you wish any of your customers to have to install Oracle software?)

DataDirect 不是一种选择,因为它需要花费一条腿和一条腿;如果您需要将单个服务器连接到大型机,它可能几乎是负担得起的.然而,期望所有客户都购买它不是一种选择.

DataDirect is not an option as it costs an arm and a leg; it may just about be affordable if you need to connect a single server to a mainframe. However it is not an option to expect all customers to buy it.

从 C# 迁移到 Java 不是一个好的选择,因为我是一名 C# 程序员并希望能够谋生!

Moving form C# to Java is not a good option, as I am a C# programmer and wish to be able to earn a living!

与大多数必须支持多个 RDBMS 的 ISV 一样,我们只需要一个允许我们使用与 SqlServer 相同的 Oracle 的小子集的解决方案.因此 System.Data.OracleClient 对我们来说已经足够强大了.

Like most ISVs that have to support multiple RDBMS we only need a solution that allows us to use the small subset of Oracle that is the same as SqlServer. Therefore System.Data.OracleClient was powerful enough for us.

(也许我们应该开始将所有数据存储在平面文件中,这样客户的 DBA 就不会再试图告诉我们如何编写软件了.Oracle DBA 更糟糕!)

(Maybe we should just start storing all data in flat files, so that customer’s DBA stop trying to tell us how to write software. Oracle DBAs are the worse!)

我真正的问题是如何编写与 Oracle 通信的 .NET 软件,我们可以轻松地将其安装为与 SqlServer 通信的 .NET 软件.不得不使用 ODP.NET 只会让 oracle 客户端安装更加痛苦,而且还会出错.

My real question is how can I write .NET software that talks to Oracle that is us pain free to installed as .NET software that talks to SqlServer. Having to use ODP.NET just makes the oracle client install yet more painful, with yet more to go wrong.

如果我使用的是 JAVA,我可以只使用 JDBC 类型 4 驱动程序.Microsoft 为 SqlServer 提供了一种,Oracle 为 Oracle 提供了一种.然而,甲骨文似乎希望尽可能难使用 .Net,而微软希望尽可能难使用甲骨文.

If I was using JAVA I could just use JDBC type 4 drivers. Microsoft provides one for SqlServer and Oracle provides one for Oracle. However it seems that Oracle wishes to make .Net usage as hard as possible and Microsoft wishes to make Oracle usage as hard as possible.

到目前为止,最佳选择看起来像 devArt 的 dotConnect.

So far the best option looks like devArt's dotConnect.

然而,我开始怀疑 .NET 是否是 ISV 的一个很好的开发系统,因为迟早您总会遇到需要 Oracle 支持的客户.在 Java 世界中,他们似乎已经解决了这个问题.

看起来 Oracle 可能即将推出一个明智的完全托管的 ADO.NET 提供程序,它甚至可能很容易安装!请参阅 此处 声称测试版 - 2011 年,生产 - 2011 年底.

It looks like Oracle may be about to bring out a senible Fully Managed ADO.NET provider themselfs it may even be easy to install! see here that claims Beta – 2011, Production – End of 2011.

推荐答案

完全托管的 ODP.NET 现在可用于生产.它非常小(小于 10MB)并且不依赖于其他文件.你可以在这里获得它:

The fully managed ODP.NET is now available in production. It is very small (less than 10MB) and is not dependent on other files. You can obtain it here:

http://www.oracle.com/technetwork/topics/dotnet/downloads/index.html

原答案:

轻松确保所需的 Oracle 客户端软件(包括 ODP.NET)在部署计算机上始终可用的一种方法是将其嵌入到您的应用程序中.由于 XCOPY ODP.NET 可用,ODP.NET 的嵌入变得更容易很多.你可以从这个链接下载它:

One way to easily ensure that the required Oracle client side software (including ODP.NET) is always available on the deployment machine is to embed it with your application. ODP.NET has gotten a lot easier to embed now that XCOPY ODP.NET is available. You can download it from this link:

http://www.oracle.com/technology/software/tech/windows/odpnet/index.html

使用 XCOPY ODP.NET,您在部署应用程序时只需执行以下操作:

With XCOPY ODP.NET, all you need to do when you deploy your application is the following:

1) 将您的应用程序复制到目标机器

1) Copy your application to the target machine

2) 运行install.bat",将几个 Oracle DLL 复制到目标机器(包括 ODP.NET 和 Oracle 客户端 (OCI) 软件)

2) Run "install.bat" which copies a couple of Oracle DLL's to the target machine (including ODP.NET and the Oracle client side (OCI) software)

3) 运行configure.bat",它会执行gacutil"并更新目标机器的注册表

3) Run "configure.bat", which does a "gacutil" and updates the registry of the target machine

4) 为您的应用程序提供连接字符串信息.您可以使用 EZCONNECT 连接字符串 ("hostname@servicename"),或者您(或您的客户)可以通过将 TNS_ADMIN 注册表项或环境变量设置为指向另一个已配置 sqlnet 连接别名的 Oracle 主目录来共享预先存在的 sqlnet 配置.

4) Provide your application with connect string information. You can use the EZCONNECT connect string ("hostname@servicename") or you (or your customer) can share preexisting sqlnet configurations by setting the TNS_ADMIN registry entry or environment variable to point to another Oracle home that has sqlnet connect aliases already configured.

就是这样!就是这么简单.

That's it! It is really that simple.

我希望您仔细查看上面链接中的 ODP.NET XCOPY,以亲自了解如今将 ODP.NET 嵌入您的应用程序是多么容易.

I hope you will take a good look at ODP.NET XCOPY in the link above to see for yourself how easy it is these days to embed ODP.NET with your app.

补充说明:

如果您选择不将 ODP.NET 嵌入您的应用程序,无论是 Microsoft OracleClient 还是 ODP.NET,都需要在任何部署计算机上安装额外的 Oracle 客户端 (OCI) 软件.这两种情况的唯一区别是,当您使用 ODP.NET 时,它还需要存在于部署机器上.好消息是,在您的客户计算机上安装的典型 Oracle 已经包含 ODP.NET.

If you choose not to embed ODP.NET with your application, in both the case of Microsoft OracleClient and in the case of ODP.NET, there needs to be additional Oracle client side (OCI) software installed on any deployment machine. The only difference between the two cases is that when you are using ODP.NET, it also needs to exist on the deployment machine. The good news is that a typical Oracle install on your customer machine will include ODP.NET already.

现在,如果您的目标机器已经安装了 ODP.NET,您不需要做任何其他事情.您只需要分发您的应用程序.如果您确实需要使用标准安装程序安装 ODP.NET,您也可以从上面提供的链接下载它.标准的 ODP.NET 安装只需几分钟即可为您配置好一切.

Now, if your target machine already has ODP.NET installed you don't need to do anything else. You just need to distribute your application. If you do need to install ODP.NET using the standard installer, you can also download it from the link provided above. The standard ODP.NET install only takes a few minutes and configures everything for you.

同样,您可以使用 EZConnect 连接字符串让网络配置变得轻而易举,或者使用 TNS_ADMIN 注册表项或环境变量来利用您的客户已经习惯使用的预先存在的连接别名.

And again, you can use EZConnect connect strings to make networking configuration a piece of cake, or use the TNS_ADMIN registry entry or environment variable to take advantage of pre-existing connect aliases that your customer is already used to using.

希望这会有所帮助,

克里斯蒂安·谢伊

甲骨文

请随时在我们的功能请求网站上提供有关此功能和其他未来功能的反馈:http://apex.oracle.com/pls/apex/f?p=18357:46

Feel free to provide your feedback on this and other future features at our feature request website: http://apex.oracle.com/pls/apex/f?p=18357:46

这篇关于如何编写适用于 SqlServer 和 Oracle 的 .Net 应用程序(现在不推荐使用 System.Data.OracleClient)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Batch multiple select statements when calling Oracle from ADO.NET(从 ADO.NET 调用 Oracle 时批处理多个选择语句)
How to get the generated id from an inserted row using ExecuteScalar?(如何使用 ExecuteScalar 从插入的行中获取生成的 id?)
Binding query parameters by name with ODP.NET(使用 ODP.NET 按名称绑定查询参数)
Why the semicolon couldn#39;t place in the CommandText of a OracleCommand when C#(为什么在 C# 时分号不能放在 OracleCommand 的 CommandText 中)
DbCommand and parameterized SQL, ORACLE vs SQL Server(DbCommand 和参数化 SQL、ORACLE 与 SQL Server)
Oracle Stored Procedure and custom data type(Oracle 存储过程和自定义数据类型)