Oracle Data Access

时间:2016-02-26 11:40:51

标签: c# .net oracle visual-studio-2012 oracle11g

我正在使用Windows 10和Oracle 11g上的Visual Studio 2012中的C#项目。 为了连接我的c#项目,我必须安装Oracle Data Access Components_ODTwithODAC121024,一切正常。

我将项目的目标.NET框架更新为3.5,现在我收到此错误:

  

无法加载文件或程序集“Oracle.DataAccess,Version = 2.121.2.0,Culture = neutral,PublicKeyToken = 89b483f429c47342”或其中一个依赖项。试图加载格式不正确的程序。

经过长时间的搜索和测试,我认为是由不兼容问题引起的。 我尝试通过程序和功能启用.NET Framework 3.5 - >打开或关闭Windows功能。

我尝试从

读取引用并导入Oracle.DataAccess.dll
  

C:\应用\萨默尔\产品\ 11.2.0 \ dbhome_1 \ ODP.NET \ BIN \ 2.x的

我还使用了Oracle数据访问组件附带的Oracle.DataAccess.dll

当我禁用处理oracle命令的方法时,我的项目工作正常。

以下是代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Oracle.DataAccess;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;

namespace backup_Check_v01
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        Read_const_File();
    }

    //Method for Reading Constants File
    public void Read_const_File()
    {
        string File_Path;
        File_Path = @"s:\test\result";
        Get_File_info(File_Path);
    }

    //Method for reading file information ex(File Name,Size,and creation date..etc)
    public void Get_File_info(string para1)
    { 
        FileInfo info = new FileInfo(para1);
        richTextBox1.AppendText(Environment.NewLine + "File Name: " + Path.GetFileNameWithoutExtension(info.Name));
        richTextBox1.AppendText(Environment.NewLine + "File Size (Bytes): " + info.Length.ToString());
        richTextBox1.AppendText(Environment.NewLine + "Creation Time: " + info.CreationTime.ToString());
        richTextBox1.AppendText(Environment.NewLine + "Last Access: " + info.LastAccessTime.ToString());
        richTextBox1.AppendText(Environment.NewLine + " **************************** ");

        search_for_string(para1);
    }

    public void search_for_string(string para2)
    {
        string keywords = "sb_0501_Thu.dmp";
        string oradb = "Data Source=sb_1901;User Id=sb_1901;Password=sb00;";

        StreamReader sr = new StreamReader(para2);
        richTextBox1.AppendText(Environment.NewLine + sr.ReadToEnd());

        if (!richTextBox1.Text.Contains(keywords))
        {
            OracleConnection conn = new OracleConnection(oradb);
            conn.Open();

            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            cmd.CommandText = "insert into backup_check(REC_ID,OFFICE_CODE,DUMP_NAME,DUMP_STATUS,SYSTEM,CHECK_DATE)values(null,null,'keywords',0,'SBank',sysdate)";
            int rowsupdated = cmd.ExecuteNonQuery();
            if (rowsupdated == 0)
            { MessageBox.Show("NONE"); }
            else
            { MessageBox.Show("Done"); }

            conn.Dispose();
        }
        else
        {
            OracleConnection conn = new OracleConnection(oradb);
            conn.Open();

            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            cmd.CommandText = "insert into backup_check(REC_ID,OFFICE_CODE,DUMP_NAME,DUMP_STATUS,SYSTEM,CHECK_DATE)values(null,null,'keywords',1,'SBank',sysdate)";
            int rowsupdated = cmd.ExecuteNonQuery();
            if (rowsupdated == 0)
            { MessageBox.Show("NONE"); }
            else
            { MessageBox.Show("Done"); }
            conn.Dispose();
        }
    }
}

}

1 个答案:

答案 0 :(得分:0)

您指的是ODP.NET版本2. 121 .2.0。但似乎您已安装Oracle客户端 11.2 。版本必须相互匹配(至少是主版本号)

打开您的* .csproj文件并设置Oracle.DataAccess的引用,如下所示:

<Reference Include="Oracle.DataAccess">
  <SpecificVersion>False</SpecificVersion>
</Reference>

不需要Version=...processorArchitecture=...等属性。您的应用程序将加载正确的Oracle.DataAccess.dll,具体取决于所选的体系结构和目标.NET框架