forum

Home / DeveloperSection / Forums / SqlBulkCopy operation hang and not responding

SqlBulkCopy operation hang and not responding

marcel ethan 3888 23-Dec-2013

I am using SqlBulkCopy to copy several tables to database. However, most of the tables are successfully copied to database except one table with 6000++ rows of data. When I run the function, it just simply hang there and not responding.

Below is my code:

using (SqlConnection destinationConnection = Login.GetConnection())
{
    destinationConnection.Open();
    using (SqlTransaction transaction = destinationConnection.BeginTransaction(IsolationLevel.ReadCommited))
    {
        using (SqlBulkCopy bulkCopy = new SqlBulkCopy(destinationConnection, SqlBulkCopyOptions.KeepIdentity, transaction))
        {
            bulkCopy.DestinationTableName = "dbo." + tableName;
            try
            {
                bulkCopy.WriteToServer(dt);
                transaction.Commit();
                bulkCopySuccess = true;
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                MessageBox.Show(ex.Message, ex.GetType().ToString());
                bulkCopySuccess = false;
            }
        }
    }
}

What is the possible problem? Is something wrong with my code?


c# c# 
Updated on 23-Dec-2013

Can you answer this question?


Answer

1 Answers

Liked By