0

执行 SqlBulkCopy 将 200k+ 记录从 Oracle 移动到 SQL。在执行 WriteToServer 时遇到将字符串转换为 guid 的错误。在 Oracle 中,该表将 guid 保存为 nvarchar(50);SQL 它是一个唯一标识符。sql 语句没有做任何花哨的事情——只是从 Oracle 源表中选择所有数据。

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);
}
4

1 回答 1

0

我认为是 FROM,而不是 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);
    }
于 2013-10-15T20:59:58.400 回答