diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml index d7299c5e80..06fdf1b5b6 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml @@ -503,15 +503,37 @@ and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. property. - + event and does not imply that this number of rows has been sent to the server or committed. This value can be accessed during or after the execution of a bulk copy operation. + +This value will wrap around and become negative if the number of rows exceeds int.MaxValue. Consider using the property. ]]> + + + The number of rows processed in the ongoing bulk copy operation. + + + The long value of the property. + + + + event and does not imply that this number of rows has been sent to the server or committed. + +This value can be accessed during or after the execution of a bulk copy operation. +]]> + + + Releases all resources used by the current instance of the diff --git a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs index 58dfd74e1e..f10c66b386 100644 --- a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs @@ -259,6 +259,8 @@ public sealed partial class SqlBulkCopy : System.IDisposable public int NotifyAfter { get { throw null; } set { } } /// public int RowsCopied { get { throw null; } } + /// + public long RowsCopied64 { get { throw null; } } /// public event Microsoft.Data.SqlClient.SqlRowsCopiedEventHandler SqlRowsCopied { add { } remove { } } /// diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs index d469427274..273394395a 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs @@ -171,7 +171,7 @@ public SourceColumnMetadata(ValueMethod method, bool isSqlType, bool isDataFeed) private readonly SqlBulkCopyOptions _copyOptions; private int _timeout = DefaultCommandTimeout; private string _destinationTableName; - private int _rowsCopied; + private long _rowsCopied; private int _notifyAfter; private int _rowsUntilNotification; private bool _insideRowsCopiedEvent; @@ -222,8 +222,8 @@ private int RowNumber private TdsParserStateObject _stateObj; private List<_ColumnMapping> _sortedColumnMappings; - private static int _objectTypeCount; // EventSource Counter - internal readonly int _objectID = Interlocked.Increment(ref _objectTypeCount); + private static int s_objectTypeCount; // EventSource Counter + internal readonly int _objectID = Interlocked.Increment(ref s_objectTypeCount); // Newly added member variables for Async modification, m = member variable to bcp. private int _savedBatchSize = 0; // Save the batchsize so that changes are not affected unexpectedly. @@ -376,7 +376,10 @@ public int NotifyAfter internal int ObjectID => _objectID; /// - public int RowsCopied => _rowsCopied; + public int RowsCopied => unchecked((int)_rowsCopied); + + /// + public long RowsCopied64 => _rowsCopied; internal SqlStatistics Statistics { diff --git a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs index 2a8197448c..ca229487be 100644 --- a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs @@ -215,6 +215,8 @@ public sealed partial class SqlBulkCopy : System.IDisposable public int NotifyAfter { get { throw null; } set { } } /// public int RowsCopied { get { throw null; } } + /// + public long RowsCopied64 { get { throw null; } } /// public event Microsoft.Data.SqlClient.SqlRowsCopiedEventHandler SqlRowsCopied { add { } remove { } } /// diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs index 81ccfb570a..4ae02c29d6 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs @@ -186,7 +186,7 @@ public SourceColumnMetadata(ValueMethod method, bool isSqlType, bool isDataFeed) private readonly SqlBulkCopyOptions _copyOptions; private int _timeout = DefaultCommandTimeout; private string _destinationTableName; - private int _rowsCopied; + private long _rowsCopied; private int _notifyAfter; private int _rowsUntilNotification; private bool _insideRowsCopiedEvent; @@ -238,8 +238,8 @@ private int RowNumber private TdsParserStateObject _stateObj; private List<_ColumnMapping> _sortedColumnMappings; - private static int _objectTypeCount; // EventSource Counter - internal readonly int _objectID = Interlocked.Increment(ref _objectTypeCount); + private static int s_objectTypeCount; // EventSource Counter + internal readonly int _objectID = Interlocked.Increment(ref s_objectTypeCount); // Newly added member variables for Async modification, m = member variable to bcp. private int _savedBatchSize = 0; // Save the batchsize so that changes are not affected unexpectedly. @@ -392,7 +392,10 @@ public int NotifyAfter internal int ObjectID => _objectID; /// - public int RowsCopied => _rowsCopied; + public int RowsCopied => unchecked((int)_rowsCopied); + + /// + public long RowsCopied64 => _rowsCopied; internal SqlStatistics Statistics { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs index 8527b49115..88931ad5fe 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs @@ -8,34 +8,19 @@ namespace Microsoft.Data.SqlClient public class SqlRowsCopiedEventArgs : System.EventArgs { private bool _abort; - private long _rowsCopied; + private readonly long _rowsCopied; /// - public SqlRowsCopiedEventArgs(long rowsCopied) - { - _rowsCopied = rowsCopied; - } + public SqlRowsCopiedEventArgs(long rowsCopied) => _rowsCopied = rowsCopied; /// public bool Abort { - get - { - return _abort; - } - set - { - _abort = value; - } + get => _abort; + set => _abort = value; } /// - public long RowsCopied - { - get - { - return _rowsCopied; - } - } + public long RowsCopied => unchecked((int)_rowsCopied); } } diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReader1.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReader1.cs index 2e43147789..9dea10c9e4 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReader1.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReader1.cs @@ -36,6 +36,7 @@ public static void Test(string srcConstr, string dstConstr, string dstTable) bulkcopy.WriteToServer(reader); DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 5, "Unexpected number of rows."); + DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied64, (long)5, "Unexpected number of rows."); } Helpers.VerifyResults(dstConn, dstTable, 3, 5); } diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReaderAsync.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReaderAsync.cs index 8f55cb1710..cdeffa2e89 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReaderAsync.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReaderAsync.cs @@ -52,6 +52,7 @@ private static async Task TestAsync(string srcConstr, string dstConstr, string d await outputSemaphore.WaitAsync(); DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 5, "Unexpected number of rows."); + DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied64, (long)5, "Unexpected number of rows."); } Helpers.VerifyResults(dstConn, dstTable, 3, 5); }