SQLServer 2012中的SqlBulkCopy失败

时间:2016-11-24 16:33:29

标签: c# sql-server-2012 sqlbulkcopy

我的下面的代码正在我的SQL Server 2008上运行,但在SQL Server 2012中也是如此。没有异常或错误,数据没有插入到表中。

using(var bulkCopy = new SqlBulkCopy(objsqlConnection.ConnectionString, SqlBulkCopyOptions.KeepNulls & SqlBulkCopyOptions.KeepIdentity)) {
    bulkCopy.ColumnMappings.Clear();
    bulkCopy.BatchSize = Dttable.Rows.Count;

    foreach(DataColumn col in Dttable.Columns) {
        bulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName);
    }

    bulkCopy.BulkCopyTimeout = 600;
    bulkCopy.DestinationTableName = Servertable;
    destinationTbName = Servertable;

    bulkCopy.SqlRowsCopied += new SqlRowsCopiedEventHandler(OnSqlRowsTransfer);
    bulkCopy.NotifyAfter = Dttable.Rows.Count;

    bulkCopy.WriteToServer(Dttable);

    return true;
}

这是否与权限相关?我该如何解决?请帮忙

0 个答案:

没有答案