Performing SqlBulkCopy to move 200k+ records from Oracle to SQL. Running into error converting a string a guid when performing WriteToServer. In Oracle the table saves the guid as nvarchar(50); SQL it's a unique identifier. The sql statement is doing nothing fancy - just selecting all data from the Oracle source table.
public void BulkCopyFromOrl(OracleDataReader rdr, string targetTableName)
{
// open Sql connection
var _con = GetConnection();
// Sql Bulk Copy instance
var _bc = new SqlBulkCopy(_con);
// set destination table
_bc.DestinationTableName = targetTableName;
// set batch size (optional)
_bc.BatchSize = 10000;
// set time out (optional)
_bc.BulkCopyTimeout = 600;
// write to server
_bc.WriteToServer(rdr);
// close and dispose
_bc.Close();
// close and dispose
Terminate(null, _con);
}
public SqlDataReader GetSourceData(string tableName)
{
// todo: should be parameterized but for demonstration in the console app,
// just add columns and table name
var sql = string.Format("SELECT {0} FORM {1}", MappedColumns(), tableName);
return ExecuteReader(sql);
}