Skip to content

SqlBulkCopy.RowsCopied overflows because it is an int #2001

@madelson

Description

@madelson

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Up-for-Grabs 🙌Issues that are ready to be picked up for anyone interested. Please self-assign and remove the label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions