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
{
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;
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;
}
}
}
}