SQLBulkCopy Oracle to SQL Guid error

sql sqlbulkcopy

Question

SqlBulkCopy is used to transfer more than 200k records from Oracle to SQL. Having trouble converting a string to a guid when using the WriteToServer command. The GUID is saved in the database in Oracle as nvarchar(50); in SQL, it is a unique identifier. Simple data selection from the Oracle source table is all that the SQL query does.

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

I believe it is FROM, not FORM:

  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