Describe the bug
SqlBulkCopy.RowsCopied is supposed to return "The number of rows processed in the ongoing bulk copy operation". However, because it is Int32 rather than Int64 like SqlRowsCopiedEventArgs.RowsCopied, it is prone to overflow into the negative with very large copy operations (something we're currently running into).
This makes it difficult to track the actual number of rows copied.
Furthermore, the internal int field behind this property also flows into the event args, resulting in negative values there even though the data type is long.
To reproduce
- Run a SqlBulkCopy operation with > int.MaxValue rows.
- Observe SqlBulkCopy.RowsCopied after the fact (and/or observe the SqlRowsCopied event's args)
Expected behavior
Ideally, both properties would be long and would only overflow after long.MaxValue rows copied, which seems extremely unlikely to happen. Given that we probably can't change the type of the RowsCopied property at this point, what would be nice to see is:
- Internally the rows are tracked as
long so that the event args has the right value
- A new
long RowsCopied64 property is added to SqlBulkCopy that returns the underlying value as long.
Further technical details
Microsoft.Data.SqlClient version: multiple
.NET target: .NET 6
SQL Server version: SQL Server 2019
Operating system: Windows 10
Describe the bug
SqlBulkCopy.RowsCopiedis supposed to return "The number of rows processed in the ongoing bulk copy operation". However, because it isInt32rather thanInt64likeSqlRowsCopiedEventArgs.RowsCopied, it is prone to overflow into the negative with very large copy operations (something we're currently running into).This makes it difficult to track the actual number of rows copied.
Furthermore, the internal
intfield behind this property also flows into the event args, resulting in negative values there even though the data type islong.To reproduce
Expected behavior
Ideally, both properties would be
longand would only overflow afterlong.MaxValuerows copied, which seems extremely unlikely to happen. Given that we probably can't change the type of theRowsCopiedproperty at this point, what would be nice to see is:longso that the event args has the right valuelong RowsCopied64property is added toSqlBulkCopythat returns the underlying value aslong.Further technical details
Microsoft.Data.SqlClient version: multiple
.NET target: .NET 6
SQL Server version: SQL Server 2019
Operating system: Windows 10