代码之家  ›  专栏  ›  技术社区  ›  Xinus

从.NET连接到Oracle 10g

  •  2
  • Xinus  · 技术社区  · 15 年前

    我正在尝试连接到位于某个IP地址的Oracle服务器,但始终会出现以下错误

    System.TypeInitialization异常: 的类型初始值设定项 'oracle.dataaccess.client.oracleConnection' 引发了异常。---gt; oracle.dataaccess.client.oracleexception 提供程序与不兼容 Oracle客户端的版本 oracle.dataaccess.client.oracleinit.initialize() 在 oracle.dataaccess.client.oracleconnection..cctor() ---内部异常堆栈跟踪结束---在oracle.dataaccess.client.oracleconnection..ctor(字符串 连接字符串)在 webapplication1.\u默认值。页面加载(对象 发件人,事件args e)在 C:\users\sunil\documents\Visual Studio 2008\projects\webapplication1\webapplication1\default.aspx.cs:行 二十六

    这是一份测试文件

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using Oracle.DataAccess.Client;
    namespace WebApplication1
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                try {
                    string oradb = "Data Source=(DESCRIPTION=(ADDRESS_LIST="
                    + "(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.11)(PORT=1523)))"
                    + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=ORCL)));"
                    + "User Id=<user id>;Password=<some password>;";
    
                    OracleConnection conn = new OracleConnection(oradb); // C#
                    conn.Open();
    
                }
                catch (Exception  ex){
                    Label1.Text = ex.ToString();
                }
    
            }
        }
    }
    

    我已经安装了 Oracle 10GR2客户端 Oracle 10GR2提供程序 对于下面的ASP.NET Windows Vista . 我有什么遗漏吗?

    问题部分解决了我在提供程序之后安装了Oracle客户端

    …但现在例外显示为

    oracle.dataaccess.client.oracleexception 在 oracle.dataaccess.client.oracleexception.handleerrorhelper(int32 错误代码,oracleconnection conn,intptr OpserrCtx,OpoSqlValCtx公司* poposqlvalctx,对象src,字符串 程序)在 oracle.dataaccess.client.oracleexception.handleerror(int32 错误代码,oracleconnection conn,intptr opserrctx,对象src)在 oracle.dataaccess.client.oracleconnection.open() 在 webapplication1.\u默认值。页面加载(对象 发件人,事件args e)在 C:\users\sunil\documents\Visual Studio 2008\projects\webapplication1\webapplication1\default.aspx.cs:行 二十八

    3 回复  |  直到 15 年前
        1
  •  2
  •   Xinus    15 年前

    问题解决了…Windows Vista安全性(?)是不是我作为管理员运行程序,一切正常

        2
  •  0
  •   itowlson    15 年前

    看起来您的Oracle.DataAccess.dll版本与Oracle客户端安装不同步。例如,您可能正在使用Oracle.DataAccess.dll的最新版本,该版本需要Oracle 11客户端。

    检查Oracle.DataAccess.dll的版本字符串。我相信oracle 10 dll的版本是“10.x.y.z”,而oracle11dll的版本是“2.x.y.z”(是的,这很混乱)。

    注意这是 服务器版本控制问题——这个错误是在OracleConnection类尝试初始化自己时发生的,而这要比它与服务器对话早得多。

        3
  •  0
  •   Bob    15 年前

    您可以尝试查看asp.net是否具有对Oracle文件夹的权限,这可能是造成这种情况的原因