Sohaib Akhtar
Sohaib Akhtar

Reputation: 205

I need progressbar with SQLBulkcopy

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.

Upvotes: 2

Views: 3904

Answers (1)

Conrad Frix
Conrad Frix

Reputation: 52645

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

Upvotes: 4

Related Questions