SqlBulkCopy hangs without any exception or timeout when inserting a datatable with even a single row

c# sqlbulkcopy

Question

Having an issue, basically I have a very large datatable (50,000 rows) and I am using SqlBulkCopy to insert it via this function I wrote:

public static void DoSqlBulkCopy(string connectionString, string destinationTableName, DataTable dataTable, int batchSize = 2000)
{
    using (var bulk = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.CheckConstraints))
    {
        bulk.BatchSize = batchSize;
        bulk.DestinationTableName = destinationTableName;

        for (int i = 0; i < dataTable.Columns.Count; i++)
        {
            bulk.ColumnMappings.Add(dataTable.Columns[i].ColumnName, dataTable.Columns[i].ColumnName);
        }

        bulk.WriteToServer(dataTable);
    }
}

This code has worked for other stuff but on this dataset it just hangs on WriteToServer.

I scratched my chin for a bit and fired up the SQL profiler but there is no activity.

Any suggestions? It doesn't timeout either, I left it overnight.

Accepted Answer

Fixed it. Spelt the table name wrong, was inserting into CuteCats instead of CuteCat. It hung with no error message. Blasted thing!




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why