SQLBulkCopy Oracle to SQL Guid error

sql sqlbulkcopy

Question

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);
}
1
0
10/15/2013 8:58:31 PM

Popular Answer

It's FROM, not FORM i think :

  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} FROM {1}", MappedColumns(), tableName);
        return ExecuteReader(sql);
    }
0
10/15/2013 8:59:58 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow