Click here to Skip to main content
15,171,439 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=, 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()
                // 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];
                SaveUsingOracleBulkCopy("tFinal", dt);
            catch (Exception ex)
                Console.Write("Error is " + ex.ToString());

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

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

Updated 5-Jul-18 3:40am
Richard MacCutchan 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

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

This is the best solution I have come across.

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