Click here to Skip to main content
16,021,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to insert csv file content by reading it through File.ReadAllLines() and storing it into DataTable.
After storing this, I am calling OracleBulkCopy to insert all records into my Table.

I have used framework 4 for .NET and Oracle 11g version.

This gives me error saying "
Could not load file or assembly 'Oracle.DataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342' 
"

Help me to find out what exactly I am missing here.

I am attaching code for reference.

What I have tried:

using System;
using System.Data;
using System.IO;  
using System.Configuration;
using Oracle.DataAccess.Client;


namespace ImportCSV
{
    class Program
    {
        static void Main()
        {
            try
            {
                // your code here 
                string CSVFilePathName = @"C:\TempShare\TestCSVFile.csv";
                
                string[] Lines = File.ReadAllLines(CSVFilePathName);
                string[] Fields;
                Fields = Lines[0].Split(new char[] { ',' });
                int Cols = Fields.GetLength(0);
                DataTable dt = new DataTable();
                DataRow Row;
                //1st row must be column names; force lower case to ensure matching later on.
                for (int i = 0; i < Cols; i++)
                {
                    dt.Columns.Add(Fields[i].ToLower(), typeof(string));
                }
                for (int i = 1; i < Lines.GetLength(0); i++)
                {
                    Fields = Lines[i].Split(new char[] { ',' });
                    Row = dt.NewRow();
                    for (int f = 0; f < Cols; f++)
                        Row[f] = Fields[f];
                    dt.Rows.Add(Row);
                }
                SaveUsingOracleBulkCopy("tFinal", dt);
                
            }
            catch (Exception ex)
            {
                Console.Write("Error is " + ex.ToString());
                throw;
            }
        }

        static void SaveUsingOracleBulkCopy(string destTableName, DataTable dt)
        {
            try
            {
                string oradb = "Data Source=(DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=000.00.00.00)(PORT=0000)) (CONNECT_DATA =(SID=XX))); User Id=XXX;Password=xxxxxxx;";
                using (var connection = new OracleConnection(oradb))
                {
                    connection.Open();
                    Console.WriteLine("Connected to Oracle Database {0}", connection.ServerVersion);
                    Console.WriteLine("Press RETURN to exit.");
                    Console.ReadLine();

                    using (var bulkCopy = new OracleBulkCopy(connection, OracleBulkCopyOptions.UseInternalTransaction))
                    {
                        bulkCopy.DestinationTableName = destTableName;
                        bulkCopy.BulkCopyTimeout = 600;
                        bulkCopy.WriteToServer(dt);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }   

    }
}
Posted
Updated 5-Jul-18 2:40am
v2
Comments
[no name] 4-Jul-18 7:42am    
The message is quite clear, you are missing an Oracle library component.
Nutan R 5-Jul-18 8:42am    
True. I found a better approach at https://stackoverflow.com/questions/33509331/oracle-dataaccess-client-dependencies

 
Share this answer
 
c# - Oracle.DataAccess.Client Dependencies - Stack Overflow[^]

This is the best solution I have come across.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900