使用Oracle.DataClient时provider与Oracle客户端版本不兼容报错
我使用的是 Visual Studio 2008 Express Edition,并且正在尝试使用 Oracle.DataClient 开发一个小型应用程序.尝试连接到目标系统中的数据库时,出现上述错误.
I'm using Visual Studio 2008 Express Edition, and I'm trying my hand in developing a small application using Oracle.DataClient. I'm getting the above mentioned error, when trying to connect to the database in the target system.
我为 Oracle 10gR2 添加了对 Oracle ODP.net 提供程序的引用,并且在目标机器中我安装了 Oracle 10gR2 数据库的副本.尽管如此,我还是收到了错误消息.在发布之前,我阅读了这篇文章 在 SO,并且我已经安装了即时客户端,错误仍然存在.以下是完整的错误堆栈.
I've added a reference to Oracle ODP.net provider for Oracle 10gR2, and in the target machine I have a copy of Oracle 10gR2 database installed. Despite this, I'm getting the error. Before posting this, I read this post at SO, and I have installed the instant client, the error persists. Below is the full error stack.
************** Exception Text **************
System.TypeInitializationException: The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception. ---> Oracle.DataAccess.Client.OracleException The provider is not compatible with the version of Oracle client at Oracle.DataAccess.Client.OracleInit.Initialize()
at Oracle.DataAccess.Client.OracleConnection..cctor()
--- End of inner exception stack trace ---
at Oracle.DataAccess.Client.OracleConnection..ctor(String connectionString)
at Employees1.frmLogin.oralogin()
at Employees1.frmLogin.btnTest_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
API Data Conversion Assistant
Assembly Version: 0.0.0.1
Win32 Version: 0.0.0.1
CodeBase: file:///C:/Documents%20and%20Settings/3i/My%20Documents/My%20Dropbox/Sathya's%20dropbox/VisualStudio%20Releases/APIDataconversion/Application%20Files/API%20Data%20Conversion%20Assistant_0_0_0_3/API%20Data%20Conversion%20Assistant.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
Oracle.DataAccess
Assembly Version: 2.102.2.20
Win32 Version: 2.102.2.20
我在开发应用程序的机器上安装了 Oracle 11g,在那里运行良好,但在目标机器上,我收到此错误.任何输入将不胜感激.
I have Oracle 11g installed on the machine on which I developed the application, and it works fine there, but on the target machine, I'm getting this error. Any inputs will be appreciated.
PS:如上所述,引用的 Oracle.DataClient.dll 文件版本对应的是 10gR2,而不是 11g.
PS: As mentioned above, the referenced Oracle.DataClient.dll file version corresponds to 10gR2, not 11g.
推荐答案
我一直在进一步研究这个问题,你只需要从同一个下载的 ODP.Net 版本中获取所有适当的 DLL 并将它们放入与您的 Exe 文件相同的文件夹,因为 ODP.Net 对不混合版本号很挑剔,这就是您看到的问题(要么完全丢失,要么完全丢失 oci.dll,在这种情况下,它会令人讨厌地给出相同的错误).
I've been looking into this problem further, and you simply need to grab all the appropriate DLL's from the same downloaded version of ODP.Net and put them in the same folder as your Exe file, because ODP.Net is fussy about not mixing version numbers, which is the problem you're seeing (either that or the oci.dll is totally missing, in which case it annoyingly gives the same error).
我在这里解释了如何做到这一点:http://splinter.com.au/using-the-new-odpnet-to-access-oracle-from-c不过,这是它的要点:
I've explained how to do this here: http://splinter.com.au/using-the-new-odpnet-to-access-oracle-from-c Here's the gist of it though:
- 下载http://www.oracle.com/technology/software/tech/windows/odpnet/index1110710beta.html
- 解压文件
- 解压其中的所有 JAR
- 获取这些刚刚解压的 dll:oci.dll(从'oci.dll.dbl'重命名)Oracle.DataAccess.dlloraociicus11.dllOraOps11w.dllorannzsbb11.dlloraocci11.dllociw32.dll(从'ociw32.dll.dbl'重命名)
- 将所有 DLL 放在与 C# 可执行文件相同的文件夹中
相关文章