@@ -1689,6 +1689,7 @@ public void WriteToServer(DbDataReader reader)
1689
1689
try
1690
1690
{
1691
1691
statistics = SqlStatistics . StartTimer ( Statistics ) ;
1692
+ ResetWriteToServerGlobalVariables ( ) ;
1692
1693
_rowSource = reader ;
1693
1694
_dbDataReaderRowSource = reader ;
1694
1695
_sqlDataReaderRowSource = reader as SqlDataReader ;
@@ -1697,10 +1698,8 @@ public void WriteToServer(DbDataReader reader)
1697
1698
{
1698
1699
_rowSourceIsSqlDataReaderSmi = _sqlDataReaderRowSource is SqlDataReaderSmi ;
1699
1700
}
1700
- _dataTableSource = null ;
1701
1701
_rowSourceType = ValueSourceType . DbDataReader ;
1702
1702
1703
- _isAsyncBulkCopy = false ;
1704
1703
WriteRowSourceToServerAsync ( reader . FieldCount , CancellationToken . None ) ; //It returns null since _isAsyncBulkCopy = false;
1705
1704
}
1706
1705
finally
@@ -1728,16 +1727,15 @@ public void WriteToServer(IDataReader reader)
1728
1727
try
1729
1728
{
1730
1729
statistics = SqlStatistics . StartTimer ( Statistics ) ;
1730
+ ResetWriteToServerGlobalVariables ( ) ;
1731
1731
_rowSource = reader ;
1732
1732
_sqlDataReaderRowSource = _rowSource as SqlDataReader ;
1733
1733
if ( _sqlDataReaderRowSource != null )
1734
1734
{
1735
1735
_rowSourceIsSqlDataReaderSmi = _sqlDataReaderRowSource is SqlDataReaderSmi ;
1736
1736
}
1737
1737
_dbDataReaderRowSource = _rowSource as DbDataReader ;
1738
- _dataTableSource = null ;
1739
1738
_rowSourceType = ValueSourceType . IDataReader ;
1740
- _isAsyncBulkCopy = false ;
1741
1739
WriteRowSourceToServerAsync ( reader . FieldCount , CancellationToken . None ) ; //It returns null since _isAsyncBulkCopy = false;
1742
1740
}
1743
1741
finally
@@ -1768,13 +1766,12 @@ public void WriteToServer(DataTable table, DataRowState rowState)
1768
1766
try
1769
1767
{
1770
1768
statistics = SqlStatistics . StartTimer ( Statistics ) ;
1769
+ ResetWriteToServerGlobalVariables ( ) ;
1771
1770
_rowStateToSkip = ( ( rowState == 0 ) || ( rowState == DataRowState . Deleted ) ) ? DataRowState . Deleted : ~ rowState | DataRowState . Deleted ;
1772
1771
_rowSource = table ;
1773
1772
_dataTableSource = table ;
1774
- _sqlDataReaderRowSource = null ;
1775
1773
_rowSourceType = ValueSourceType . DataTable ;
1776
1774
_rowEnumerator = table . Rows . GetEnumerator ( ) ;
1777
- _isAsyncBulkCopy = false ;
1778
1775
1779
1776
WriteRowSourceToServerAsync ( table . Columns . Count , CancellationToken . None ) ; //It returns null since _isAsyncBulkCopy = false;
1780
1777
}
@@ -1809,16 +1806,14 @@ public void WriteToServer(DataRow[] rows)
1809
1806
try
1810
1807
{
1811
1808
statistics = SqlStatistics . StartTimer ( Statistics ) ;
1812
-
1809
+ ResetWriteToServerGlobalVariables ( ) ;
1813
1810
DataTable table = rows [ 0 ] . Table ;
1814
1811
Debug . Assert ( null != table , "How can we have rows without a table?" ) ;
1815
1812
_rowStateToSkip = DataRowState . Deleted ; // Don't allow deleted rows
1816
1813
_rowSource = rows ;
1817
1814
_dataTableSource = table ;
1818
- _sqlDataReaderRowSource = null ;
1819
1815
_rowSourceType = ValueSourceType . RowArray ;
1820
1816
_rowEnumerator = rows . GetEnumerator ( ) ;
1821
- _isAsyncBulkCopy = false ;
1822
1817
1823
1818
WriteRowSourceToServerAsync ( table . Columns . Count , CancellationToken . None ) ; //It returns null since _isAsyncBulkCopy = false;
1824
1819
}
@@ -1851,7 +1846,7 @@ public Task WriteToServerAsync(DataRow[] rows, CancellationToken cancellationTok
1851
1846
try
1852
1847
{
1853
1848
statistics = SqlStatistics . StartTimer ( Statistics ) ;
1854
-
1849
+ ResetWriteToServerGlobalVariables ( ) ;
1855
1850
if ( rows . Length == 0 )
1856
1851
{
1857
1852
TaskCompletionSource < object > source = new TaskCompletionSource < object > ( ) ;
@@ -1872,7 +1867,6 @@ public Task WriteToServerAsync(DataRow[] rows, CancellationToken cancellationTok
1872
1867
_rowStateToSkip = DataRowState . Deleted ; // Don't allow deleted rows
1873
1868
_rowSource = rows ;
1874
1869
_dataTableSource = table ;
1875
- _sqlDataReaderRowSource = null ;
1876
1870
_rowSourceType = ValueSourceType . RowArray ;
1877
1871
_rowEnumerator = rows . GetEnumerator ( ) ;
1878
1872
_isAsyncBulkCopy = true ;
@@ -1908,10 +1902,10 @@ public Task WriteToServerAsync(DbDataReader reader, CancellationToken cancellati
1908
1902
try
1909
1903
{
1910
1904
statistics = SqlStatistics . StartTimer ( Statistics ) ;
1905
+ ResetWriteToServerGlobalVariables ( ) ;
1911
1906
_rowSource = reader ;
1912
1907
_sqlDataReaderRowSource = reader as SqlDataReader ;
1913
1908
_dbDataReaderRowSource = reader ;
1914
- _dataTableSource = null ;
1915
1909
_rowSourceType = ValueSourceType . DbDataReader ;
1916
1910
_isAsyncBulkCopy = true ;
1917
1911
resultTask = WriteRowSourceToServerAsync ( reader . FieldCount , cancellationToken ) ; // It returns Task since _isAsyncBulkCopy = true;
@@ -1946,10 +1940,10 @@ public Task WriteToServerAsync(IDataReader reader, CancellationToken cancellatio
1946
1940
try
1947
1941
{
1948
1942
statistics = SqlStatistics . StartTimer ( Statistics ) ;
1943
+ ResetWriteToServerGlobalVariables ( ) ;
1949
1944
_rowSource = reader ;
1950
1945
_sqlDataReaderRowSource = _rowSource as SqlDataReader ;
1951
1946
_dbDataReaderRowSource = _rowSource as DbDataReader ;
1952
- _dataTableSource = null ;
1953
1947
_rowSourceType = ValueSourceType . IDataReader ;
1954
1948
_isAsyncBulkCopy = true ;
1955
1949
resultTask = WriteRowSourceToServerAsync ( reader . FieldCount , cancellationToken ) ; // It returns Task since _isAsyncBulkCopy = true;
@@ -1990,9 +1984,9 @@ public Task WriteToServerAsync(DataTable table, DataRowState rowState, Cancellat
1990
1984
try
1991
1985
{
1992
1986
statistics = SqlStatistics . StartTimer ( Statistics ) ;
1987
+ ResetWriteToServerGlobalVariables ( ) ;
1993
1988
_rowStateToSkip = ( ( rowState == 0 ) || ( rowState == DataRowState . Deleted ) ) ? DataRowState . Deleted : ~ rowState | DataRowState . Deleted ;
1994
1989
_rowSource = table ;
1995
- _sqlDataReaderRowSource = null ;
1996
1990
_dataTableSource = table ;
1997
1991
_rowSourceType = ValueSourceType . DataTable ;
1998
1992
_rowEnumerator = table . Rows . GetEnumerator ( ) ;
@@ -3212,5 +3206,17 @@ private Task WriteToServerInternalAsync(CancellationToken ctoken)
3212
3206
}
3213
3207
return resultTask ;
3214
3208
}
3209
+
3210
+ private void ResetWriteToServerGlobalVariables ( )
3211
+ {
3212
+ _dataTableSource = null ;
3213
+ _dbDataReaderRowSource = null ;
3214
+ _isAsyncBulkCopy = false ;
3215
+ _rowEnumerator = null ;
3216
+ _rowSource = null ;
3217
+ _rowSourceType = ValueSourceType . Unspecified ;
3218
+ _sqlDataReaderRowSource = null ;
3219
+ _sqlDataReaderRowSource = null ;
3220
+ }
3215
3221
}
3216
3222
}
0 commit comments