You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is is difficult to find out how many rows SqlBulkCopy.WriteToServer[Async] has copied. This is a problem when using streaming as DbDataReader doesn't provide this information either.
Describe the solution you'd like
class SqlBulkCopy
{
...
public long RowsCopied { get; }
...
}
It would be cleaner to change the return type of WriteToServer[Async] to long, but I think this would technically be a breaking change? This would also have the advantage of not having to worry about multiple calls or reads before writing.
Describe alternatives you've considered
setting NotifyAfter to 1, subscribing to SqlRowsCopied and then storing it somewhere from the event handler. Cons: overhead of calling a delegate, plus the allocation of EventArgs per row.
fully buffer to a DataTable. Cons: whole dataset in memory.
wrapping IDataReader and keeping count of the number of times Read() is called. Cons:
doesn't work for async readers.
wrapping DbDataReader. Cons: lots of boilerplate, can't call protected methods on the source leading to unintended behaviour divergence.
SELECT COUNT(*) FROM DESTINATION. Cons: network round trip, concurrency issues.
Reflecting on the private _rowsCopied field. Cons: reflection, brittle.
This is a good suggestion, we currently use reflection to access this field because we don't wan't to have the overhead of an event for every row copied just to get the count.
It is is difficult to find out how many rows
SqlBulkCopy.WriteToServer[Async]
has copied. This is a problem when using streaming asDbDataReader
doesn't provide this information either.Describe the solution you'd like
It would be cleaner to change the return type of
WriteToServer[Async]
tolong
, but I think this would technically be a breaking change? This would also have the advantage of not having to worry about multiple calls or reads before writing.Describe alternatives you've considered
NotifyAfter
to 1, subscribing toSqlRowsCopied
and then storing it somewhere from the event handler. Cons: overhead of calling a delegate, plus the allocation ofEventArgs
per row.DataTable
. Cons: whole dataset in memory.IDataReader
and keeping count of the number of times Read() is called. Cons:doesn't work for async readers.
DbDataReader
. Cons: lots of boilerplate, can't call protected methods on the source leading to unintended behaviour divergence.SELECT COUNT(*) FROM DESTINATION
. Cons: network round trip, concurrency issues._rowsCopied
field. Cons: reflection, brittle.Additional context
The text was updated successfully, but these errors were encountered: