使用ODP.NET部署ASP.NET网站

时间:2014-09-05 08:29:54

标签: c# asp.net oracle odp.net

我在写完更多类似问题之后写这篇文章:

OracleException (0x80004005) When Connecting to Oracle Database

The provider is not compatible with the version of Oracle client

我有一个小型的ASP.NET网站,它在开发人员计算机上运行良好但在一台测试服务器中有效。什么时候应用程序调用OracleConnection.Open();我得到一个相当无助的“未处理的执行错误”。完整描述如下:

在我的机器(开发者机器)中,它就像一个魅力,但在测试服务器上,它不能很好地工作。

我的规格

Developer Machine&测试服务器:Win 7,IIS7,Oracle Instant Client 11.2.0.4,.NET Framework 4.0 UAT&生产数据库:Oracle 9i标准版 我在Bin文件夹中有DLL(

我的目标

不要在部署计算机中安装Oracle客户端,而只是复制DLL。

我尝试了什么:

  • 我安装了最新的Microsoft Visual C ++ 2012 Redistributable(x86)

  • 将Platform Target的项目设置设置为x86

  • 好的检查是否是IIS问题,我制作了一个简单的C#Winforms应用程序,并且它与EXE一起复制了所有DLL。我在调用OracleConnection.Open()时运行它,引发了异常并且它的一些属性为空。

在我的C#Winform应用程序中,我编写了以下代码:

private void btnConnect_Click(object sender, EventArgs e)
        {

            string conStr = string.Format(oraConStr, txtHost.Text, txtPwd.Text, txtUser.Text);
            using (OracleConnection con = new OracleConnection(conStr))
            {
                LogMessage(conStr);
                try
                {
                    con.Open();
                    MessageBox.Show("Connected");
                }
                catch (OracleException OraEr)
                {
                    displayOracleErrorMessage(OraEr);
                }
                catch (Exception Er)
                {
                    MessageBox.Show(Er.Message);
                }
            }


        }

        private void displayOracleErrorMessage(OracleException er)
        {
            MessageBox.Show(string.Format("Error {0}\nError Number {1}\nStack Trace{1}", er.Message, er.Number, er.StackTrace));
        }

当我运行上面的应用程序时,发生异常,但是Exception在其错误消息,错误号和错误源的属性中具有空值,因此我得到“对象引用未设置为类的实例“错误。即Oracle.DataAccess.Client.OracleException.get_Number()

有关调用的详细信息,请参阅此消息的结尾 实时(JIT)调试而不是此对话框。

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at Oracle.DataAccess.Client.OracleException.get_Number()
   at OracleConnectionChecker.Form1.displayOracleErrorMessage(OracleException er) in d:\TEMP\Test 2013\Projects\OracleConnectionChecker\OracleConnectionChecker\Form1.cs:line 54
   at OracleConnectionChecker.Form1.btnConnect_Click(Object sender, EventArgs e) in d:\TEMP\Test 2013\Projects\OracleConnectionChecker\OracleConnectionChecker\Form1.cs:line 41
   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: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
OracleConnectionChecker
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Executable/Debug/OracleConnectionChecker.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
Oracle.DataAccess
    Assembly Version: 4.112.4.0
    Win32 Version: 4.112.4.0
    CodeBase: file:///C:/Executable/Debug/Oracle.DataAccess.DLL
----------------------------------------
System.Data
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Core
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Transactions
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.Transactions/v4.0_4.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.Configuration
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.EnterpriseServices
    Assembly Version: 4.0.0.0
    Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
    CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_32/System.EnterpriseServices/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

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

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
  服务器错误。      

未处理的执行错误说明:未处理的异常   在执行当前Web请求期间发生。请   查看堆栈跟踪以获取有关错误和位置的更多信息   它起源于代码。

     

异常详细信息:Oracle.DataAccess.Client.OracleException:

     

来源错误:

     

执行期间生成了未处理的异常   当前的网络请求。有关的来源和位置的信息   可以使用下面的异常堆栈跟踪来识别异常。

     

堆栈追踪:

     

[OracleException(0x80004005)]
  Oracle.DataAccess.Client.OracleException.HandleErrorHelper(的Int32   errCode,OracleConnection conn,IntPtr opsErrCtx,OpoSqlValCtx *   pOpoSqlValCtx,Object src,String procedure,Boolean bCheck)+1467
  Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode,   OracleConnection conn,IntPtr opsErrCtx,Object src)+24
  Oracle.DataAccess.Client.OracleConnection.Open()+4444
  JksbBoWeb2.Default.getMainDataSet(DateTime pStartDate,DateTime   pEndDate)+296 JksbBoWeb2.Default.btnToday_Click(对象发送者,   EventArgs e)+133 JksbBoWeb2.Default.Page_Load(Object sender,   EventArgs e)+28
  System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,   EventArgs e)+51 System.Web.UI.Control.OnLoad(EventArgs e)+92
  System.Web.UI.Control.LoadRecursive()+54
  System.Web.UI.Page.ProcessRequestMain(布尔   includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)   772

     

----------------------------------------------- ---------------------------------版本信息:Microsoft .NET Framework版本:4.0.30319;   ASP.NET版本:4.0.30319.18408

好好想想我是否错过了我的webconfig中的任何内容,我发布了同样的内容

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <appSettings>
    <add key="ChartImageHandler" value="storage=file;timeout=20;dir=c:\TempImageFiles\;" />
  </appSettings>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="ChartImageHandler" />
      <add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST"
        path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </handlers>
  </system.webServer>
  <system.web>
    <httpHandlers>
      <add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        validate="false" />
    </httpHandlers>
    <pages>
      <controls>
        <add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting"
          assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
      </controls>
    </pages>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </assemblies>
    </compilation>
    <authentication mode="Forms">
      <forms loginUrl="login.aspx" name=".ASPXFORMSAUTH"/>
    </authentication>
    <authorization>
      <deny users="?"/>
    </authorization>
  </system.web>
  <connectionStrings>
    <add name="ora.prod.jksb.com" connectionString="DATA SOURCE=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=x)(PORT=1521)))(CONNECT_DATA=(SID = ORCL)));PASSWORD=x;USER ID=x;" providerName="Oracle.DataAccess.Client"/>
    <add name="ora.uat.jksb.com" connectionString="DATA SOURCE=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=x)(PORT=1521)))(CONNECT_DATA=(SID = ORCL)));PASSWORD=x;USER ID=x;" providerName="Oracle.DataAccess.Client"/>
  </connectionStrings>
</configuration>

2 个答案:

答案 0 :(得分:2)

为了方便起见:你不能。 ODP.NET(Oracle.DataAccess.Client)使用OCI,即来自Oracle的库,用于处理实际连接。这不是一个.NET程序集,它在C ++中。 ODP.NET只是一个调用OCI的包装器。这就是您必须安装客户端工具的原因。

但还有更多。 Oracle发布了Managed ODP.NET,它是协议的完整实现(而不仅仅是OCI的包装器)。这意味着您不必安装客户端工具,只需包含该单个程序集即可完成!

答案 1 :(得分:2)

解决了这个问题。

我发现部署服务器中已经安装了Old Oracle 9i client,这会导致与Oracle部署相关的冲突。我只是卸载了Oracle 9i客户端,删除了PATH中的引用,最后删除了注册表中的HKLM\SOFTWARE\ORACLE密钥,它确实有效!

相关问题