当前位置:编程学习 > C#/ASP.NET >>

C#采用无客户端访问Oracle,出现System.AccessViolationException: 尝试读取或写入受保护的内存

客户要求我们的应用不安装客户端访问Oracle数据库,我是把oci.dll、ociw32.dll、Oracle.DataAccess.dll、orannzsbb10.dll、oraocci10.dll、oraociei10.dll、OraOps10.dll
放入安装文件夹,然后用System.Data.OracleClient访问Oracle
但问题来了,如果电脑上没有安装Oracle客户端或服务器,没问题能正常访问;如果电脑上装装Oracle客户端或服务器,偶尔会出现下列异常:
************** 异常文本 **************
System.AccessViolationException: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
   在 System.Data.Common.UnsafeNativeMethods.OCIEnvCreate(IntPtr& envhpp, MODE mode, IntPtr ctxp, IntPtr malocfp, IntPtr ralocfp, IntPtr mfreefp, UInt32 xtramemsz, IntPtr usrmempp)
   在 System.Data.OracleClient.TracedNativeMethods.OCIEnvCreate(IntPtr& envhpp, MODE mode)
   在 System.Data.OracleClient.OciHandle..ctor(OciHandle parentHandle, HTYPE handleType, MODE ocimode, HANDLEFLAG handleflags)
   在 System.Data.OracleClient.OracleInternalConnection.OpenOnLocalTransaction(String userName, String password, String serverName, Boolean integratedSecurity, Boolean unicode, Boolean omitOracleConnectionName)
   在 System.Data.OracleClient.OracleInternalConnection..ctor(OracleConnectionString connectionOptions)
   在 System.Data.OracleClient.OracleConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
   在 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
   在 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
   在 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
   在 System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
   在 System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
   在 System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   在 System.Data.OracleClient.OracleConnection.Open()
   在 DCM.util.Functions.CreateDbConnection()
   在 DCM.form.FormLogin.ExecuteLogin(Object sender, EventArgs e)
   在 DCM.util.Functions.ButtonHandlerNoRepeat(Object sender, EventArgs e, EventHandler Handler, Boolean ret)
   在 DCM.form.FormLogin.btnLogin_Click(Object sender, EventArgs e)
   在 System.Windows.Forms.Control.OnClick(EventArgs e)
   在 System.Windows.Forms.Button.OnClick(EventArgs e)
   在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   在 System.Windows.Forms.Control.WndProc(Message& m)
   在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
   在 System.Windows.Forms.Button.WndProc(Message& m)
   在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** 已加载的程序集 **************
mscorlib
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5456 (Win7SP1GDR.050727-5400)
    基本代码: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
DCM
    程序集版本: 1.0.0.0
    Win32 版本: 1.0.0.0
    基本代码: file:///C:/Program%20Files/citics/DCM/DCM.exe
----------------------------------------
System.Windows.Forms
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5460 (Win7SP1GDR.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5456 (Win7SP1GDR.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5462 (Win7SP1GDR.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Data
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Data.OracleClient
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_32/System.Data.OracleClient/2.0.0.0__b77a5c561934e089/System.Data.OracleClient.dll
----------------------------------------
System.Data.OracleClient.resources
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
    基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Data.OracleClient.resources/2.0.0.0_zh-CHS_b77a5c561934e089/System.Data.OracleClient.resources.dll
----------------------------------------
System.Configuration
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Transactions
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.4927 (NetFXspW7.050727-4900)
    基本代码: file:///C:/Windows/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------
mscorlib.resources
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5456 (Win7SP1GDR.050727-5400)
    基本代码: file:///C:/Windows/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
System.Windows.Forms.resources
    程序集版本: 2.0.0.0
    Win32 版本: 2.0.50727.5420 (Win7SP1.050727-5400)
    基本代码: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms.resources/2.0.0.0_zh-CHS_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------

************** JIT 调试 **************
要启用实时(JIT)调试,
该应用程序或计算机的 .config 文件(machine.config)的 system.windows.forms 节中必须设置
jitDebugging 值。
编译应用程序时还必须启用
调试。

例如: 

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

启用 JIT 调试后,任何无法处理的异常
都将被发送到在此计算机上注册的 JIT 调试器,
而不是由此对话框处理。
--------------------编程问答-------------------- 怀疑是库文件版本不兼容。 --------------------编程问答-------------------- 已经装客户端的情况下,把这六个dll加上会出错,去掉就好了。 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 从安装的客户端里面把这几个dll拿出来 然后卸掉客户端试试呢?
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,