NibblyPig
NibblyPig

Reputation: 52922

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

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.

Upvotes: 3

Views: 1869

Answers (1)

NibblyPig
NibblyPig

Reputation: 52922

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

Upvotes: 2

Related Questions