2012-10-19 210 views
0
OS: Windows 7 64bit 
VB: Visual Studio 2010 
Oracle Client: 11g 

我正在开发一个连接到Oracle 11g服务器的应用程序。我可以通过Oracle SQL Developer,ODBC(在SYSWOW64中)和VB Server Explorer连接到Oracle服务器。VB.NET问题连接到Oracle 11g

我使用位于.NET参考Oracle.DataAccess:C:\ ORACLE \产品\ 11.2.0 \ client_32 \ ODP.NET \ BIN \ 2.X \ Oracle.DataAccess.dll

我试图将.DLL文件添加到我的bin文件夹中,正如其他问题所建议的那样,这不起作用。

有没有人有任何其他建议?

当我运行我的应用程序,我得到如下: enter image description here

下面是详细信息:

System.TypeInitializationException was unhandled 
    Message=The type initializer for 'Oracle.DataAccess.Client.OracleConnection' threw an exception. 
    Source=Oracle.DataAccess 
    TypeName=Oracle.DataAccess.Client.OracleConnection 
    StackTrace: 
     at Oracle.DataAccess.Client.OracleConnection..ctor(String connectionString) 
     at Orc_Test_1.Form1.Button1_Click(Object sender, EventArgs e) in c:\Visual Studio 2010\Projects\Orc_Test_1\Orc_Test_1\Form1.vb:line 9 
     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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
     at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 
     at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 
     at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) 
     at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() 
     at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() 
     at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) 
     at Orc_Test_1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) 
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
     at System.Threading.ThreadHelper.ThreadStart() 
    InnerException: Oracle.DataAccess.Client.OracleException 
     DataSource="" 
     ErrorCode=-2147467259 
     Message=The provider is not compatible with the version of Oracle client 
     Number=-11 
     Procedure="" 
     Source=Oracle Data Provider for .NET 
     StackTrace: 
      at Oracle.DataAccess.Client.OracleInit.Initialize() 
      at Oracle.DataAccess.Client.OracleConnection..cctor() 
     InnerException: 

VB.NET代码:

Imports System.Data 
Imports Oracle.DataAccess.Client ' ODP.NET Oracle managed provider 
Imports Oracle.DataAccess.Types 

Public Class Form1 

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click 
     Dim oradb As String = "Data Source=SERVER1;Persist Security Info=True;User ID=username;Password=password;Unicode=True" 'From Server Explorer 
     'Dim oradb As String = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=Server1.host.net)(PORT=1522))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=Server1))); USER ID = username;Password = password;" 'From TNSnames.ora 
     Dim conn As New OracleConnection(oradb) '<--- Error happens on this line 
     conn.Open() 
     Dim cmd As New OracleCommand 
     cmd.Connection = conn 
     cmd.CommandText = "select system_id from schema1.system_impacted where system_name = AWESOME" 
     cmd.CommandType = CommandType.Text 
     Dim dr As OracleDataReader = cmd.ExecuteReader() 
     dr.Read() 
     Label1.Text = dr.Item("system_id") 
     conn.Dispose() 
    End Sub 
End Class 

回答

1

我删除了“控制面板”的“程序”部分中提供的所有Oracle客户端。然后,我进入注册表中搜索“Oracle”,并删除了Oracle客户端的所有实例/引用。在3个小时的注册表删除和重新启动后,我安装了11g客户端,并且所有事情都按预期工作。

注意:当在注册表中搜索“Oracle”时,可能会引用VB版本的Oracle或对“Oracle”的Crytsal Reports驱动程序的引用。我没有删除这些。因此,请注意文件位置和/或您正在删除的注册表项的语法。

/阅读。有用。

1

通常发生在你”重新构建x64应用程序,该应用程序正试图获取x32驱动程序,但实际上并不工作。

你在这种情况下做什么(这是相当痛苦):

  • 安装X32的Oracle客户端oraclehome1
  • 安装64位的Oracle客户端oraclehome2

确保您的应用程序的构建( x64,x32)指向正确的oraclehome。我没有那个方便的代码,但我相信它是连接字符串或类似内容中的“Home = oraclehome2”的行。

+0

快速测试会切换到x32构建目标并查看是否可以连接。 – b0rg

+0

我试过目标CPU在任何,X86和X64,我仍然得到相同的错误。 –

3

我感觉到你的痛苦,只是在部署情况下经历了类似的事情。您可能安装了多个客户端,并且您的环境正在为较旧的版本提供dll(即使您的项目中正确引用了最新的oracle.dataaccess.dll)。解决这个问题是一回事,一个prod部署服务器是另一个。不知道你的部署情况是什么,但这是对我有用的。

在尝试升级现有oracle主页中的odp.net之后,添加新的Oracle主目录等,我发现修复所有问题的最简单方法是从Oracle下载最新的odac with xcopy deployment,然后按照自述文件(并参阅here这也是一篇较旧的文章)。基本上你会运行一个install.bat文件来设置本地(在单独的文件夹中,我的是c:\ oracle_odac),然后改变你的项目引用来指向这个新文件夹中的oracle.dataaccess.dll(我用4代替2.x),然后将新文件夹的bin目录添加到路径前面(c:\ oracle_odac \ bin和c:\ oracle_odac \ odp.net \ bin \ 4)。在你的部署服务器上,你只需要复制整个c:\ oracle_odac文件夹(通过xcopy或者),然后设置路径。

也就是说,我急切地等待Oracle的fully managed odp.net的产品发布(现在beta版)。

编辑:只要补充一点,你可以避免与路径混淆,如果你在你的应用程序或网页配置文件dllpath设置。例如:

<configuration> 
... 
    <configSections> 
     <section name="oracle.dataaccess.client" type="System.Data.Common.DbProviderConfigurationHandler, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 
... 

<oracle.dataaccess.client> 
    <settings> 
     <add name="DllPath" value="c:\oracle_odac\bin"/> 
    </settings> 
    </oracle.dataaccess.client> 
... 

这将覆盖其他设置,如注册表或machine.config。它将允许多个odp.net配置和平地存在,并允许每个应用程序指向它在同一台服务器上所需的版本。

0

下载ODAC 32/ODAC 64位,取决于OS,VS和oracle 11g的兼容性。 使用oracle 11g 32,os 32位,oracle 32位或oracle 64位,os 64位和oracle 11g 64位。

0

根据我的经验,在尝试tbone的建议之后,使用PATH env变量和其他不成功的游戏,立即生效的解决方案是保存vb.net的同一文件夹右下方8个DLL文件的副本然后在同一个文件夹中添加对Oracle.DataAccess.dll的引用。

C:\Users\Legarcia\Documents\Visual Studio 2010\Projects\LabRetention\LabRetention\bin\Debug>dir *.dll 
Volume in drive C is OS 
Volume Serial Number is 10EC-8C5D 

Directory of C:\Users\Legarcia\Documents\Visual Studio 2010\Projects\LabRetention\LabRetention\bin\Debug 

09/30/2008 07:57 PM   348,160 msvcr71.dll 
10/01/2008 02:22 AM   520,192 oci.dll 
10/01/2008 01:56 AM   352,256 ociw32.dll 
08/12/2009 07:13 AM   1,011,712 Oracle.DataAccess.dll 
09/18/2008 08:47 PM   1,130,496 orannzsbb11.dll 
10/01/2008 01:48 AM   868,352 oraocci11.dll 
10/01/2008 02:45 AM  117,604,352 oraociei11.dll 
08/12/2009 07:21 AM   413,696 OraOps11w.dll 
       8 File(s) 122,249,216 bytes 
       0 Dir(s) 238,127,943,680 bytes free 

在开发/测试/调试运行,该组DLL被复制到.. \项目\ {您的项目} \ BIN \调试

例如:C:\用户\ Legarcia \文件\ Visual Studio 2010的\项目\ LabRetention \ LabRetention \ BIN \调试]

和释放,为用户的应用程序时,就在DLL文件复制到你的EXE

这似乎隔离所有其他奥拉客户端安装的同一目录。

VB.net应用程序中使用的连接字符串是从某些其他客户端目录上的TNSNAMES.ORA文件中的信息创建的。

问候。

LE +