I need progressbar with SQLBulkcopy

c# progress-bar sqlbulkcopy

Question

I need progress bar for my application. I am uploading data through text file into SQL Server but it takes a lot of time and also i used background worker for the same but that's not working properly so i just need to know is there any way i can use progress bar with SQL Bulk Copy and it tells me that's 2000 records inserted? Here is my code:

 public void bulkinsert(string tablename, DataTable dt)
    {
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }
        SqlBulkCopy blkcopy = new SqlBulkCopy(con);
        blkcopy.DestinationTableName = tablename;
        blkcopy.BatchSize = dt.Rows.Count;
        blkcopy.BulkCopyTimeout = 1500;
        blkcopy.WriteToServer(dt);
        blkcopy.Close();

    }

I really appreciate your responses.

1
2
6/30/2016 6:49:48 PM

Accepted Answer

You need to handle the SqlBulkCopy.SqlRowsCopied event which

Occurs every time that the number of rows specified by the NotifyAfter property have been processed.

I would also use Async Await and use a Progress<T> instead of a background worker

3
6/30/2016 7:03:36 PM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow