question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Give SqlBulkCopy._rowsCopied a public getter

See original GitHub issue

Is your feature request related to a problem? Please describe.

SqlBulkCopy has a private member field for the number of rows copied (_rowsCopied), which is incremented with each record copy operation. Currently, to make use of this in client code, the solution is either to use the SqlRowsCopiedEventHandler (cumbersome and potentially expensive); or use reflection to get the value out of the private member field (hacky).

Describe the solution you’d like

Create a public property backed by _rowsCopied with a public getter - SqlBulkCopy.RowsCopied { get { return _rowsCopied; } }.

Or replace _rowsCopied with a public property with a public getter - SqlBulkCopy.RowsCopied { get; }

Describe alternatives you’ve considered

The SqlRowsCopiedEventHandler; using reflection to get the value out of the private member field; doing a SQL COUNT() before and after copying.

Additional context

Doesn’t make sense to me to have a setter method for this property, but open to anyone’s justification for it they think there should be!

Class in question: https://github.com/dotnet/SqlClient/blob/master/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
mikependoncommented, Jul 9, 2020

@cheenamalhotra - thank you for pushing this fix on v2.0. This is quite an important property exposure for SqlBulkCopy class that I mainly used on RepoDb.

1reaction
chrisaliottacommented, Feb 26, 2020

@cheenamalhotra Chances are, if they’re using BulkCopy it’s because they want to get the most performance possible for copying data. Attaching and handling an Event definitely slows down this process depending on how many times the event is fired or evaluated – as such, it’s a performance limitation.

I’d imagine that they use reflection after the BulkCopy process rather than having to incur a performance hit of handling the events during the copy process. In other words, they don’t care about tracking the progress; they just want to know at the end of the routine how many rows were copied.

Absent of handling the event, and storing the outcome, the best way to do this is through accessing the property by way of reflection (from what I understand).

Read more comments on GitHub >

github_iconTop Results From Across the Web

sql server - SQLBulkCopy Row Count When Complete
I am using SQLBulkCopy to move large amounts of data. I implemented the notification event to notify me every time a certain number...
Read more >
SqlBulkCopy.SqlRowsCopied Event (System.Data.SqlClient)
Occurs every time that the number of rows specified by the NotifyAfter property have been processed. public: event System::Data::SqlClient:: ...
Read more >
SqlBulkCopy.NotifyAfter Property (System.Data.SqlClient)
The NotifyAfter property is set so that the event handler is called after every 50 rows copied to the table. In this example,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found