diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml
index 6c643017da..31e025fa4e 100644
--- a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml
+++ b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml
@@ -471,6 +471,25 @@ and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data.
]]>
+
+
+ The number of rows processed in the ongoing bulk copy operation.
+
+
+ The integer value of the
+
+ property.
+
+
+ event and does not imply that this number of rows has been sent to the server or committed.
+
+During the execution of a bulk copy operation, this value can be accessed, but it cannot be changed. Any attempt to change it will throw an .
+]]>
+
+
Releases all resources used by the current instance of the
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 22297b4dc7..726ff3427c 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
@@ -395,6 +395,15 @@ public event SqlRowsCopiedEventHandler SqlRowsCopied
}
}
+ ///
+ public int RowsCopied
+ {
+ get
+ {
+ return _rowsCopied;
+ }
+ }
+
internal SqlStatistics Statistics
{
get
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 ca46138662..72db681eb0 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
@@ -471,6 +471,15 @@ public event SqlRowsCopiedEventHandler SqlRowsCopied
}
+ ///
+ public int RowsCopied
+ {
+ get
+ {
+ return _rowsCopied;
+ }
+ }
+
internal SqlStatistics Statistics
{
get
@@ -2906,18 +2915,18 @@ private void CopyBatchesAsyncContinuedOnError(bool cleanupParser)
{
tdsReliabilitySection.Start();
#endif //DEBUG
- if ((cleanupParser) && (_parser != null) && (_stateObj != null))
- {
- _parser._asyncWrite = false;
- Task task = _parser.WriteBulkCopyDone(_stateObj);
- Debug.Assert(task == null, "Write should not pend when error occurs");
- RunParser();
- }
+ if ((cleanupParser) && (_parser != null) && (_stateObj != null))
+ {
+ _parser._asyncWrite = false;
+ Task task = _parser.WriteBulkCopyDone(_stateObj);
+ Debug.Assert(task == null, "Write should not pend when error occurs");
+ RunParser();
+ }
- if (_stateObj != null)
- {
- CleanUpStateObject();
- }
+ if (_stateObj != null)
+ {
+ CleanUpStateObject();
+ }
#if DEBUG
}
finally
diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug84548.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug84548.cs
index 35ecee4374..b41feb55fc 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug84548.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug84548.cs
@@ -62,7 +62,8 @@ public static void Test(string srcConstr, string dstConstr, string targettable)
ColumnMappings.Add("CustomerID", "CustomerID");
bulkcopy.WriteToServer(reader);
- bulkcopy.Close();
+
+ DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 1, "Unexpected number of rows.");
}
}
}
diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug85007.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug85007.cs
index 833b996637..f9983bc8d7 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug85007.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug85007.cs
@@ -90,6 +90,8 @@ public static void Test(string srcConstr, string dstConstr, string dstTable)
ColumnMappings.Add("ShipCountry", "ShipCountry");
bulkcopy.WriteToServer(reader);
+
+ DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 830, "Unexpected number of rows.");
}
Helpers.VerifyResults(dstConn, dstTable, 14, 830);
}
diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug98182.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug98182.cs
index b831679815..c6e629b40a 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug98182.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/Bug98182.cs
@@ -47,8 +47,9 @@ public static void Test(string constr, string dstTable)
ColumnMappings.Add("col 2", "[col 2]");
bulkcopy.WriteToServer(reader);
+
+ DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 1, "Unexpected number of rows.");
}
-
Helpers.VerifyResults(dstConn, dstTable, 2, 1);
}
}
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 3e8f41a1cb..2e43147789 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReader1.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReader1.cs
@@ -34,6 +34,8 @@ public static void Test(string srcConstr, string dstConstr, string dstTable)
ColumnMappings.Add("FirstName", "col3");
bulkcopy.WriteToServer(reader);
+
+ DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 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 99e25c5af4..8f55cb1710 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReaderAsync.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReaderAsync.cs
@@ -49,8 +49,10 @@ private static async Task TestAsync(string srcConstr, string dstConstr, string d
bulkcopy.DestinationTableName = dstTable;
await bulkcopy.WriteToServerAsync(reader);
+ await outputSemaphore.WaitAsync();
+
+ DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 5, "Unexpected number of rows.");
}
- await outputSemaphore.WaitAsync();
Helpers.VerifyResults(dstConn, dstTable, 3, 5);
}
}