执行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);
}
答案 0 :(得分: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);
}