简体   繁体   English

连接 Oracle 数据库失败

[英]Connecting with Oracle Database fails

Code:代码:

private void Button_Click_6(object sender, RoutedEventArgs e)
{
    TimerView tobj = new TimerView();
    tobj.Show();
    string OracleServer = "Data Source=(DESCRIPTION="
+ "(ADDRESS=(PROTOCOL=TCP)(HOST=DLDT-0897.nectechnologies.in)(PORT=1521))"
+ "(CONNECT_DATA=(SERVICE_NAME=XE)));"
+ "User ID=system;Password=abc@1234;";
     public bool Open()
{
    try
    {
        conn = new OracleConnection(OracleServer);
        conn.Open();
        return true;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    return false;
}

Error in conn.Open() : conn.Open()错误:

Warning 1 There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "Oracle.DataAccess, Version=4.112.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64", "AMD64".警告 1 正在构建的项目的处理器架构“MSIL”与参考“Oracle.DataAccess, Version=4.112.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342, processorArchitecture=AMD64”, “ AMD64"。 This mismatch may cause runtime failures.这种不匹配可能会导致运行时失败。 Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.请考虑通过配置管理器更改项目的目标处理器架构,以便在您的项目和参考之间对齐处理器架构,或者依赖于具有匹配项目目标处理器架构的处理器架构的参考。 WpfApplication应用程序

The ODP.NET package comes in two flavors: one for 32 bits programs and one for 64 bit programs. ODP.NET 包有两种风格:一种用于 32 位程序,一种用于 64 位程序。 You have to pick one when you compile since else you might end up in trouble when running the program.您必须在编译时选择一个,否则您可能会在运行程序时遇到麻烦。 So you have to switch from MSIL to 32-bits mode preferably (to support both processor architectures).因此,您必须最好从 MSIL 切换到 32 位模式(以支持两种处理器架构)。 You need to include the 32-bits version of ODP.NET then (now you are using 64-bits).您需要包含 ODP.NET 的 32 位版本(现在您使用的是 64 位)。

A better option might be to use the managed ODP.NET library, which supports both processor architectures since it doesn't depend on OCI any more.更好的选择可能是使用托管 ODP.NET 库,它支持两种处理器架构,因为它不再依赖于 OCI。 You can find the latest version here .您可以在此处找到最新版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM