forked from dotnet/SqlClient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SqlBulkCopy.xml
1394 lines (1226 loc) · 69.4 KB
/
SqlBulkCopy.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<docs>
<members name="SqlBulkCopy">
<SqlBulkCopy>
<summary>
Lets you efficiently bulk load a SQL Server table with data from another source.
</summary>
<remarks>
<format ttype="text/markdown"><![CDATA[
## Remarks
Microsoft SQL Server includes a popular command-prompt utility named **bcp** for moving data from one table to another, whether on a single server or between servers. The <xref:Microsoft.Data.SqlClient.SqlBulkCopy> class lets you write managed code solutions that provide similar functionality. There are other ways to load data into a SQL Server table (INSERT statements, for example), but <xref:Microsoft.Data.SqlClient.SqlBulkCopy> offers a significant performance advantage over them. The <xref:Microsoft.Data.SqlClient.SqlBulkCopy> class can be used to write data only to SQL Server tables. However, the data source is not limited to SQL Server; any data source can be used, as long as the data can be loaded to a <xref:System.Data.DataTable> instance or read with a <xref:System.Data.IDataReader> instance. <xref:Microsoft.Data.SqlClient.SqlBulkCopy> will fail when bulk loading a <xref:System.Data.DataTable> column of type <xref:System.Data.SqlTypes.SqlDateTime> into a SQL Server column whose type is one of the date/time types added in SQL Server 2008.
## Examples
The following console application demonstrates how to load data using the <xref:Microsoft.Data.SqlClient.SqlBulkCopy> class.
In this example, a <xref:Microsoft.Data.SqlClient.SqlDataReader> is used to copy data from the **Production.Product** table in the SQL Server **AdventureWorks** database to a similar table in the same database.
> [!IMPORTANT]
> This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](/sql/connect/ado-net/sql/bulk-copy-example-setup).
This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance,
it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data.
[!code-csharp[BulkCopy.Single#1](~/../sqlclient/doc/samples/SqlBulkCopy_Single.cs#1)]
]]></format>
</remarks>
</SqlBulkCopy>
<ctor name="SqlConnectionParameter">
<param name="connection">
The already open
<see cref="T:Microsoft.Data.SqlClient.SqlConnection" />
instance that will be used to perform the bulk copy operation. If your connection string does not use
<see langword="Integrated Security = true" />
, you can use
<see cref="T:Microsoft.Data.SqlClient.SqlCredential" />
to pass the user ID and password more securely than by specifying the user ID and password as text in the connection string.
</param>
<summary>
Initializes a new instance of the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
class using the specified open instance of
<see cref="T:Microsoft.Data.SqlClient.SqlConnection" />
.
</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Because the connection is already open when the <xref:Microsoft.Data.SqlClient.SqlBulkCopy> instance is initialized, the connection remains open after the <xref:Microsoft.Data.SqlClient.SqlBulkCopy> instance is closed.
If the `connection` argument is null, an <xref:System.ArgumentNullException> is thrown.
## Examples
The following console application demonstrates how to bulk load data using a connection that is already open. In this example, a <xref:Microsoft.Data.SqlClient.SqlDataReader>
is used to copy data from the **Production.Product** table in the SQL Server **AdventureWorks** database to a similar table in the same database. This example is for demonstration
purposes only. You would not use `SqlBulkCopy` to move data from one table to another in the same database in a production application.
Note that the source data does not have to be located on SQL Server; you can use any data source that can be read to an <xref:System.Data.IDataReader> or loaded to a
<xref:System.Data.DataTable>.
> [!IMPORTANT]
> This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](/sql/connect/ado-net/sql/bulk-copy-example-setup).
This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a
Transact-SQL `INSERT … SELECT` statement to copy the data.
[!code-csharp[BulkCopy.Single#1](~/../sqlclient/doc/samples/SqlBulkCopy_Single.cs#1)]
]]></format>
</remarks>
</ctor>
<ctor name="SqlConnectionAndSqlBulkCopyOptionAndSqlTransactionParameters">
<param name="connection">
The already open
<see cref="T:Microsoft.Data.SqlClient.SqlConnection" />
instance that will be used to perform the bulk copy. If your connection string does not use
<see langword="Integrated Security = true" />
, you can use
<see cref="T:Microsoft.Data.SqlClient.SqlCredential" />
to pass the user ID and password more securely than by specifying the user ID and password as text in the connection string.
</param>
<param name="copyOptions">
A combination of values from the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopyOptions" />
enumeration that determines which data source rows are copied to the destination table.
</param>
<param name="externalTransaction">
An existing
<see cref="T:Microsoft.Data.SqlClient.SqlTransaction" />
instance under which the bulk copy will occur.
</param>
<summary>
Initializes a new instance of the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
class using the supplied existing open instance of
<see cref="T:Microsoft.Data.SqlClient.SqlConnection" />
. The
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
instance behaves according to options supplied in the
<paramref name="copyOptions" />
parameter. If a non-null
<see cref="T:Microsoft.Data.SqlClient.SqlTransaction" />
is supplied, the copy operations will be performed within that transaction.
</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If options include `UseInternalTransaction` and the `externalTransaction` argument is not null, an **InvalidArgumentException** is thrown.
For examples demonstrating how to use `SqlBulkCopy` in a transaction, see [Transaction and Bulk Copy Operations](/sql/connect/ado-net/sql/transaction-bulk-copy-operations).
]]></format>
</remarks>
<related type="Article" href="https://msdn.microsoft.com/library/83a7a0d2-8018-4354-97b9-0b1d99f8342b">
Performing Bulk Copy Operations
</related>
<related type="Article" href="/sql/connect/ado-net/overview-sqlclient-driver">
Overview of the SqlClient driver
</related>
</ctor>
<ctor name="ConnectionStringParameter">
<param name="connectionString">
The string defining the connection that will be opened for use by the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
instance.
If your connection string does not use
<see langword="Integrated Security = true" />
, you can use
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.#ctor(Microsoft.Data.SqlClient.SqlConnection)" />
or
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.#ctor(Microsoft.Data.SqlClient.SqlConnection,Microsoft.Data.SqlClient.SqlBulkCopyOptions,Microsoft.Data.SqlClient.SqlTransaction)" />
and
<see cref="T:Microsoft.Data.SqlClient.SqlCredential" />
to pass the user ID and password more securely than by specifying the user ID and password as text in the connection string.
</param>
<summary>
Initializes and opens a new instance of
<see cref="T:Microsoft.Data.SqlClient.SqlConnection" />
based on the supplied
<paramref name="connectionString" />
. The constructor uses the
<see cref="T:Microsoft.Data.SqlClient.SqlConnection" />
to initialize a new instance of the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
class.
</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The connection is automatically closed at the end of the bulk copy operation.
If `connectionString` is null, an <xref:System.ArgumentNullException> is thrown. If `connectionString` is an empty string, an <xref:System.ArgumentException> is thrown.
## Examples
The following console application demonstrates how to bulk load data by using a connection specified as a string. The connection is automatically
closed when the <xref:Microsoft.Data.SqlClient.SqlBulkCopy> instance is closed.
In this example, the source data is first read from a SQL Server table to a <xref:Microsoft.Data.SqlClient.SqlDataReader> instance.
The source data does not have to be located on SQL Server; you can use any data source that can be read to an <xref:System.Data.IDataReader> or loaded to a <xref:System.Data.DataTable>.
> [!IMPORTANT]
> This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](/sql/connect/ado-net/sql/bulk-copy-example-setup).
This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance,
it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data.
[!code-csharp[SqlBulkCopy.ConnectionString#1](~/../sqlclient/doc/samples/SqlBulkCopy_ConnectionString.cs#1)]
]]></format>
</remarks>
<exception cref="System.ArgumentException">
If `connectionString` is an empty string, an
<see cref="System.ArgumentException" />
is thrown.
</exception>
</ctor>
<ctor name="ConnectionStringAndSqlBulkCopyOptionsParameters">
<param name="connectionString">
The string defining the connection that will be opened for use by the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
instance. If your connection string does not use
<see langword="Integrated Security = true" />
, you can use
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.#ctor(Microsoft.Data.SqlClient.SqlConnection)" />
or
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.#ctor(Microsoft.Data.SqlClient.SqlConnection,Microsoft.Data.SqlClient.SqlBulkCopyOptions,Microsoft.Data.SqlClient.SqlTransaction)" />
and
<see cref="T:Microsoft.Data.SqlClient.SqlCredential" />
to pass the user ID and password more securely than by specifying the user ID and password as text in the connection string.
</param>
<param name="copyOptions">
A combination of values from the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopyOptions" />
enumeration that determines which data source rows are copied to the destination table.
</param>
<summary>
Initializes and opens a new instance of
<see cref="T:Microsoft.Data.SqlClient.SqlConnection" />
based on the supplied
<paramref name="connectionString" />
. The constructor uses that
<see cref="T:Microsoft.Data.SqlClient.SqlConnection" />
to initialize a new instance of the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
class. The
<see cref="T:Microsoft.Data.SqlClient.SqlConnection" />
instance behaves according to options supplied in the
<paramref name="copyOptions" />
parameter.
</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
You can obtain detailed information about all the bulk copy options in the <xref:Microsoft.Data.SqlClient.SqlBulkCopyOptions> topic.
## Examples
The following console application demonstrates how to perform a bulk load by using a connection specified as a string.
An option is set to use the value in the identity column of the source table when you load the destination table. In this example,
the source data is first read from a SQL Server table to a <xref:Microsoft.Data.SqlClient.SqlDataReader> instance.
The source table and destination table each include an Identity column. By default, a new value for the **Identity** column is generated in the destination table for each row added.
In this example, an option is set when the connection is opened that forces the bulk load process to use the **Identity** values from the source table instead.
To see how the option changes the way the bulk load works, run the sample with the **dbo.BulkCopyDemoMatchingColumns** table empty. All rows load from the source.
Then run the sample again without emptying the table. An exception is thrown and the code writes a message to the console notifying you that rows weren't
added because of primary key constraint violations.
> [!IMPORTANT]
> This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](/sql/connect/ado-net/sql/bulk-copy-example-setup). This code is provided to
demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement
to copy the data.
[!code-csharp[SqlBulkCopy.KeepIdentity#1](~/../sqlclient/doc/samples/SqlBulkCopy_KeepIdentity.cs#1)]
]]></format>
</remarks>
</ctor>
<BatchSize>
<summary>
Number of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.
</summary>
<value>
The integer value of the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.BatchSize" />
property, or zero if no value has been set.
</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
A batch is complete when <xref:Microsoft.Data.SqlClient.SqlBulkCopy.BatchSize> rows have been processed or there are no more rows to send to the destination data source.
Zero (the default) indicates that each <xref:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer%2A> operation is a single batch.
If the <xref:Microsoft.Data.SqlClient.SqlBulkCopy> instance has been declared without the <xref:Microsoft.Data.SqlClient.SqlBulkCopyOptions.UseInternalTransaction> option in effect,
rows are sent to the server <xref:Microsoft.Data.SqlClient.SqlBulkCopy.BatchSize> rows at a time, but no transaction-related action is taken.
If <xref:Microsoft.Data.SqlClient.SqlBulkCopyOptions.UseInternalTransaction> is in effect, each batch of rows is inserted as a separate transaction.
The <xref:Microsoft.Data.SqlClient.SqlBulkCopy.BatchSize> property can be set at any time. If a bulk copy is already in progress, the current batch is sized according to the previous batch size.
Subsequent batches use the new size. If the <xref:Microsoft.Data.SqlClient.SqlBulkCopy.BatchSize> is initially zero and changed while a <xref:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer%2A>
operation is already in progress, that operation loads the data as a single batch. Any subsequent <xref:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer%2A>
operations on the same <xref:Microsoft.Data.SqlClient.SqlBulkCopy> instance use the new <xref:Microsoft.Data.SqlClient.SqlBulkCopy.BatchSize>.
## Examples
The following console application demonstrates how to bulk load data in batches of 50 rows. For an example illustrating how <xref:Microsoft.Data.SqlClient.SqlBulkCopy.BatchSize>
works with a transaction, see [Transaction and Bulk Copy Operations](/sql/connect/ado-net/sql/transaction-bulk-copy-operations).
> [!IMPORTANT]
> This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](/sql/connect/ado-net/sql/bulk-copy-example-setup).
This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance,
it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data.
[!code-csharp[SqlBulkCopy.BatchSize#1](~/../sqlclient/doc/samples/SqlBulkCopy_BatchSize.cs#1)]
]]></format>
</remarks>
</BatchSize>
<BulkCopyTimeout>
<summary>
Number of seconds for the operation to complete before it times out.
</summary>
<value>
The integer value of the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.BulkCopyTimeout" />
property. The default is 30 seconds. A value of 0 indicates no limit; the bulk copy will wait indefinitely.
</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If the operation does time out, the transaction is not committed and all copied rows are removed from the destination table.
## Examples
The following console application demonstrates how to modify the time-out to 60 seconds when bulk loading data.
In this example, the source data is first read from a SQL Server table to a <xref:Microsoft.Data.SqlClient.SqlDataReader> instance.
The source data does not have to be located on SQL Server; you can use any data source that can be read to an <xref:System.Data.IDataReader> or loaded to a <xref:System.Data.DataTable>.
> [!IMPORTANT]
> This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](/sql/connect/ado-net/sql/bulk-copy-example-setup).
This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a
Transact-SQL `INSERT … SELECT` statement to copy the data.
[!code-csharp[SqlBulkCopy.Timeout#1](~/../sqlclient/doc/samples/SqlBulkCopy_Timeout.cs#1)]
]]></format>
</remarks>
</BulkCopyTimeout>
<Close>
<summary>
Closes the <see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" /> instance.
</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
After you call a <xref:Microsoft.Data.SqlClient.SqlBulkCopy.Close> on the <xref:Microsoft.Data.SqlClient.SqlBulkCopy> object, no other operation will succeed. Calls to the <xref:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer%2A> method will throw an <xref:System.InvalidOperationException>. Calling the <xref:Microsoft.Data.SqlClient.SqlBulkCopy.Close> method from the <xref:Microsoft.Data.SqlClient.SqlBulkCopy.SqlRowsCopied> event causes an <xref:System.InvalidOperationException> to be thrown.
Note that open <xref:Microsoft.Data.SqlClient.SqlBulkCopy> instances are closed implicitly at the end of a `using` block.
## Examples
The following example uses the same <xref:Microsoft.Data.SqlClient.SqlBulkCopy> instance to add sales orders and their associated details to two destination tables. Because the **AdventureWorks** sales order tables are large, the sample reads only orders placed by a certain account number and bulk copies those orders and details to the destination tables. The <xref:Microsoft.Data.SqlClient.SqlBulkCopy.Close> method is used only after both bulk copy operations are complete.
> [!IMPORTANT]
> This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](/sql/connect/ado-net/sql/bulk-copy-example-setup). This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data.
[!code-csharp[SqlBulkCopy.OrdersDetails#1](~/../sqlclient/doc/samples/SqlBulkCopy_OrdersDetails.cs#1)]
]]></format>
</remarks>
</Close>
<EnableStreaming>
<summary>
Enables or disables a
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
object to stream data from an
<see cref="T:System.Data.IDataReader" />
object
</summary>
<value>
<see langword="true" />
if a
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
object can stream data from an
<see cref="T:System.Data.IDataReader" />
object; otherwise, false. The default is
<see langword="false" />
.
</value>
<remarks>
<format type="text/markdown"><![CDATA[
When <xref:Microsoft.Data.SqlClient.SqlBulkCopy.EnableStreaming> is `true`, <xref:Microsoft.Data.SqlClient.SqlBulkCopy> reads from an <xref:System.Data.IDataReader> object using <xref:System.Data.CommandBehavior.SequentialAccess>,
optimizing memory usage by using the <xref:System.Data.IDataReader> streaming capabilities. Streaming is only applicable to max data types (i.e.
VARBINARY(MAX), VARCHAR(MAX), NVARCHAR(MAX), and XML). When <xref:Microsoft.Data.SqlClient.SqlBulkCopy.EnableStreaming> is set to false,
the <xref:Microsoft.Data.SqlClient.SqlBulkCopy> class loads all the data returned by the <xref:System.Data.IDataReader> object into memory before sending it to the server.
> [!NOTE]
> The main advantage of enabling streaming is reducing memory usage during bulk copy of max data types.
]]></format>
</remarks>
</EnableStreaming>
<ColumnMappings>
<summary>
Returns a collection of
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopyColumnMapping" />
items. Column mappings define the relationships between columns in the data source and columns in the destination.
</summary>
<value>
A collection of column mappings. By default, it is an empty collection.
</value>
<remarks>
<format type="text/markdown"><![CDATA[
If the data source and the destination table have the same number of columns, and the ordinal position of each source column within the data source matches the ordinal position of
the corresponding destination column, the <xref:Microsoft.Data.SqlClient.SqlBulkCopy.ColumnMappings> collection is unnecessary. However, if the column counts differ,
or the ordinal positions are not consistent, you must use <xref:Microsoft.Data.SqlClient.SqlBulkCopy.ColumnMappings> to make sure that data is copied into the correct columns.
During the execution of a bulk copy operation, this collection can be accessed, but it cannot be changed. Any attempt to change it will throw an <xref:System.InvalidOperationException>.
]]></format>
</remarks>
</ColumnMappings>
<ColumnOrderHints>
<summary>
Returns a collection of
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopyColumnOrderHint" />
items. Column order hints describe the sort order of columns in the clustered index of the destination table.
</summary>
<value>
A collection of column order hints. By default, it is an empty collection.
</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
SqlBulkCopy's performance is improved if the data being imported is sorted according to the clustered index on the table, if any.
If the data is sorted in an order that differs from the order of a clustered index key or if there is no clustered index on the table, the order hint is ignored.
]]></format>
</remarks>
</ColumnOrderHints>
<DestinationTableName>
<summary>
Name of the destination table on the server.
</summary>
<value>
The string value of the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName" />
property, or null if none as been supplied.
</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
If <xref:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName> has not been set when <xref:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer%2A> is called, an <xref:System.ArgumentNullException>
is thrown. If <xref:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName> is modified while a <xref:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer%2A> operation is running,
the change does not affect the current operation. The new <xref:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName> value is used the next time a <xref:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer%2A> method is called.
<xref:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName> is a three-part name (`<database>.<owningschema>.<name>`). You can qualify the table name with its database and owning schema if you choose.
However, if the table name uses an underscore ("_") or any other special characters, you must escape the name using surrounding brackets as in (`[<database>.<owningschema>.<name_01>]`).
You can bulk-copy data to a temporary table by using a value such as `tempdb..#table` or `tempdb.<owner>.#table` for the <xref:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName> property.
## Examples
The following console application demonstrates how to bulk load data using a connection that is already open. The destination table is a table in the **AdventureWorks** database.
In this example, the connection is first used to read data from a SQL Server table to a <xref:Microsoft.Data.SqlClient.SqlDataReader> instance. The source data does not have to
be located on SQL Server; you can use any data source that can be read to an <xref:System.Data.IDataReader> or loaded to a <xref:System.Data.DataTable>.
> [!IMPORTANT]
> This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](/sql/connect/ado-net/sql/bulk-copy-example-setup).
This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance,
it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data.
[!code-csharp[SqlBulkCopy.Single#1](~/../sqlclient/doc/samples/SqlBulkCopy_Single.cs#1)]
]]></format>
</remarks>
</DestinationTableName>
<NotifyAfter>
<summary>
Defines the number of rows to be processed before generating a notification event.
</summary>
<value>
The integer value of the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.NotifyAfter" />
property, or zero if the property has not been set.
</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This property is designed for user interface components that illustrate the progress of a bulk copy operation. It indicates the number of rows to be processed before generating a notification event.
The <xref:Microsoft.Data.SqlClient.SqlBulkCopy.NotifyAfter> property can be set at any time, even while a bulk copy operation is underway. Changes made during a bulk copy operation take effect after
the next notification. The new setting applies to all subsequent operations on the same instance.
If <xref:Microsoft.Data.SqlClient.SqlBulkCopy.NotifyAfter> is set to a number less than zero, an <xref:System.ArgumentOutOfRangeException> is thrown.
## Examples
The following console application demonstrates how to bulk load data using a connection that is already open. The <xref:Microsoft.Data.SqlClient.SqlBulkCopy.NotifyAfter> property is set so that
the event handler is called after every 50 rows copied to the table.
In this example, the connection is first used to read data from a SQL Server table to a <xref:Microsoft.Data.SqlClient.SqlDataReader> instance. Then a second connection is opened to bulk copy the data.
Note that the source data does not have to be located on SQL Server; you can use any data source that can be read to an <xref:System.Data.IDataReader> or loaded to a <xref:System.Data.DataTable>.
> [!IMPORTANT]
> This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](/sql/connect/ado-net/sql/bulk-copy-example-setup). This code is provided to
demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT`
statement to copy the data.
[!code-csharp[SqlBulkCopy.NotifyAfter#1](~/../sqlclient/doc/samples/SqlBulkCopy_NotifyAfter.cs#1)]
]]></format>
</remarks>
</NotifyAfter>
<SqlRowsCopied>
<summary>
Occurs every time that the number of rows specified by the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.NotifyAfter" />
property have been processed.
</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Note that the settings of <xref:Microsoft.Data.SqlClient.SqlBulkCopy.NotifyAfter> and <xref:Microsoft.Data.SqlClient.SqlBulkCopy.BatchSize> are independent. Receipt of a
<xref:Microsoft.Data.SqlClient.SqlBulkCopy.SqlRowsCopied> event does not imply that any rows have been sent to the server or committed.
You cannot call SqlBulkCopy.Close (<xref:Microsoft.Data.SqlClient.SqlBulkCopy.Close>) or SqlConnection.Close (<xref:Microsoft.Data.SqlClient.SqlConnection.Close>) from this event.
Doing this will cause an <xref:System.InvalidOperationException> being thrown, and the <xref:Microsoft.Data.SqlClient.SqlBulkCopy> object state will not change. If the user wants to cancel the
operation from the event, the <xref:Microsoft.Data.SqlClient.SqlRowsCopiedEventArgs.Abort> property of the <xref:Microsoft.Data.SqlClient.SqlRowsCopiedEventArgs> can be used.
(See [Transaction and Bulk Copy Operations](/sql/connect/ado-net/sql/transaction-bulk-copy-operations) for examples that use the
<xref:Microsoft.Data.SqlClient.SqlRowsCopiedEventArgs.Abort> property.)
No action, such as transaction activity, is supported in the connection during the execution of the bulk copy operation, and it is recommended that you not use the same connection used
during the <xref:Microsoft.Data.SqlClient.SqlBulkCopy.SqlRowsCopied> event. However, you can open a different connection.
## Examples
The following console application demonstrates how to bulk load data using a connection that is already open. The <xref:Microsoft.Data.SqlClient.SqlBulkCopy.NotifyAfter> property is set so that
the event handler is called after every 50 rows copied to the table.
In this example, the connection is first used to read data from a SQL Server table to a <xref:Microsoft.Data.SqlClient.SqlDataReader> instance. Note that the source data does not have to be located on
SQL Server; you can use any data source that can be read to an <xref:System.Data.IDataReader> or loaded to a <xref:System.Data.DataTable>.
> [!IMPORTANT]
> This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](/sql/connect/ado-net/sql/bulk-copy-example-setup).
This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier
and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data.
[!code-csharp[SqlBulkCopy.NotifyAfter#1](~/../sqlclient/doc/samples/SqlBulkCopy_NotifyAfter.cs#1)]
]]></format>
</remarks>
</SqlRowsCopied>
<RowsCopied>
<summary>
The number of rows processed in the ongoing bulk copy operation.
</summary>
<value>
The integer value of the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.RowsCopied" />
property.
</value>
<remarks>
<format type="text/markdown">
<![CDATA[
## Remarks
This value is incremented during the <xref:Microsoft.Data.SqlClient.SqlBulkCopy.SqlRowsCopied> 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 <xref:Microsoft.Data.SqlClient.SqlBulkCopy.RowsCopied64> property.
]]></format>
</remarks>
</RowsCopied>
<RowsCopied64>
<summary>
The number of rows processed in the ongoing bulk copy operation.
</summary>
<value>
The long value of the <see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.RowsCopied64" /> property.
</value>
<remarks>
<format type="text/markdown">
<![CDATA[
## Remarks
This value is incremented during the <xref:Microsoft.Data.SqlClient.SqlBulkCopy.SqlRowsCopied> 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.
]]>
</format>
</remarks>
</RowsCopied64>
<System.IDisposable.Dispose>
<summary>
Releases all resources used by the current instance of the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
class.
</summary>
<remarks>
<format type="text/markdown"><![CDATA[
Call `Dispose` when you are finished using the <xref:Microsoft.Data.SqlClient.SqlBulkCopy>. The `Dispose` method leaves the <xref:Microsoft.Data.SqlClient.SqlBulkCopy> in an unusable state.
After calling `Dispose`, you must release all references to the <xref:Microsoft.Data.SqlClient.SqlBulkCopy> so the garbage collector can reclaim the memory that the
<xref:Microsoft.Data.SqlClient.SqlBulkCopy> was occupying.
For more information, see [Cleaning Up Unmanaged Resources](/dotnet/standard/garbage-collection/unmanaged) and
[Implementing a Dispose Method](/dotnet/standard/garbage-collection/implementing-dispose).
> [!NOTE]
> Always call `Dispose` before you release your last reference to the <xref:Microsoft.Data.SqlClient.SqlBulkCopy>. Otherwise, the resources it is using will not be freed until the garbage collector calls
the <xref:Microsoft.Data.SqlClient.SqlBulkCopy> object's `Finalize` method.
]]></format>
</remarks>
</System.IDisposable.Dispose>
<WriteToServer name="DbDataReaderParameter">
<param name="reader">
A
<see cref="T:System.Data.Common.DbDataReader" />
whose rows will be copied to the destination table.
</param>
<summary>
Copies all rows from the supplied
<see cref="T:System.Data.Common.DbDataReader" />
array to a destination table specified by the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName" />
property of the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
object.
</summary>
<remarks>
To be added.
</remarks>
<exception cref="T:System.InvalidOperationException">
A
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopyColumnOrderHint" />
did not specify a valid destination column name.
</exception>
</WriteToServer>
<WriteToServer name="IDataReaderParameter">
<param name="reader">
A
<see cref="T:System.Data.IDataReader" />
whose rows will be copied to the destination table.
</param>
<summary>
Copies all rows in the supplied
<see cref="T:System.Data.IDataReader" />
to a destination table specified by the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName" />
property of the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
object.
</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The copy operation starts at the next available row in the reader. Most of the time, the reader was just returned by <xref:System.Data.IDbCommand.ExecuteReader> or a similar call,
so the next available row is the first row. To process multiple results, call <xref:System.Data.IDataReader.NextResult> on the data reader and call
<xref:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer%2A> again.
Note that using <xref:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer%2A> modifies the state of the reader. The method will call <xref:System.Data.IDataReader.Read>
until it returns false, the operation is aborted, or an error occurs. This means that the data reader will be in a different state, probably at the end of the result set,
when the <xref:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer%2A> operation is complete.
While the bulk copy operation is in progress, the associated destination <xref:Microsoft.Data.SqlClient.SqlConnection> is busy serving it, and no other operations can be performed on the connection.
The <xref:Microsoft.Data.SqlClient.SqlBulkCopy.ColumnMappings> collection maps from the data reader columns to the destination database table.
## Examples
The following console application demonstrates how to bulk load data from a <xref:Microsoft.Data.SqlClient.SqlDataReader>. The destination table is a table in the **AdventureWorks** database.
> [!IMPORTANT]
> This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](/sql/connect/ado-net/sql/bulk-copy-example-setup). This code is provided
to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a
Transact-SQL `INSERT … SELECT` statement to copy the data.
[!code-csharp[SqlBulkCopy.ConnectionString#1](~/../sqlclient/doc/samples/SqlBulkCopy_ConnectionString.cs#1)]
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">
A
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopyColumnOrderHint" />
did not specify a valid destination column name.
</exception>
</WriteToServer>
<WriteToServer name="DataTableParameter">
<param name="table">
A
<see cref="T:System.Data.DataTable" />
whose rows will be copied to the destination table.
</param>
<summary>
Copies all rows in the supplied
<see cref="T:System.Data.DataTable" />
to a destination table specified by the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName" />
property of the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
object.
</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
All rows in the <xref:System.Data.DataTable> are copied to the destination table except those that have been deleted.
While the bulk copy operation is in progress, the associated destination <xref:Microsoft.Data.SqlClient.SqlConnection> is busy serving it, and no other operations can be performed on the connection.
The <xref:Microsoft.Data.SqlClient.SqlBulkCopy.ColumnMappings> collection maps from the <xref:System.Data.DataTable> columns to the destination database table.
## Examples
The following Console application demonstrates how to bulk load data from a <xref:System.Data.DataTable>. The destination table is a table in the **AdventureWorks** database.
In this example, a <xref:System.Data.DataTable> is created at run time and is the source of the `SqlBulkCopy` operation.
> [!IMPORTANT]
> This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](/sql/connect/ado-net/sql/bulk-copy-example-setup).
This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data.
[!code-csharp[SqlBulkCopy.DataTable#1](~/../sqlclient/doc/samples/SqlBulkCopy_DataTable.cs#1)]
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">
A
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopyColumnOrderHint" />
did not specify a valid destination column name.
</exception>
<related type="Article" href="https://msdn.microsoft.com/library/83a7a0d2-8018-4354-97b9-0b1d99f8342b">
Performing Bulk Copy Operations
</related>
<related type="Article" href="/sql/connect/ado-net/overview-sqlclient-driver">
Overview of the SqlClient driver
</related>
</WriteToServer>
<WriteToServer name="DataTableAndRowStateParameters">
<param name="table">
A
<see cref="T:System.Data.DataTable" />
whose rows will be copied to the destination table.
</param>
<param name="rowState">
A value from the
<see cref="T:System.Data.DataRowState" />
enumeration. Only rows matching the row state are copied to the destination.
</param>
<summary>
Copies only rows that match the supplied row state in the supplied
<see cref="T:System.Data.DataTable" />
to a destination table specified by the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName" />
property of the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
object.
</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
Only rows in the <xref:System.Data.DataTable> that are in the states indicated in the `rowState` argument and have not been deleted are copied to the destination table.
> [!NOTE]
> If <xref:System.Data.DataRowState.Deleted> is specified, any <xref:System.Data.DataRowState.Unchanged>, <xref:System.Data.DataRowState.Added>, and <xref:System.Data.DataRowState.Modified>
rows will also be copied to the server. No exception will be raised.
While the bulk copy operation is in progress, the associated destination <xref:Microsoft.Data.SqlClient.SqlConnection> is busy serving it, and no other operations can be performed on the connection.
The <xref:Microsoft.Data.SqlClient.SqlBulkCopy.ColumnMappings> collection maps from the <xref:System.Data.DataTable> columns to the destination database table.
## Examples
The following Console application demonstrates how to bulk load only the rows in a <xref:System.Data.DataTable> that match a specified state. In this case, only unchanged rows are added. The destination table is a table in the **AdventureWorks** database.
In this example, a <xref:System.Data.DataTable> is created at run time and three rows are added to it. Before the <xref:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer%2A> method is executed, one of the rows is edited.
The <xref:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer%2A> method is called with a `DataRowState.Unchanged` `rowState` argument, so only the two unchanged rows are bulk copied to the destination.
> [!IMPORTANT]
> This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](/sql/connect/ado-net/sql/bulk-copy-example-setup). This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data.
[!code-csharp[SqlBulkCopy.DataRowState#1](~/../sqlclient/doc/samples/SqlBulkCopy_DataRowState.cs#1)]
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">
A
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopyColumnOrderHint" />
did not specify a valid destination column name.
</exception>
</WriteToServer>
<WriteToServer name="DataRowParameter">
<param name="rows">An array of <see cref="T:System.Data.DataRow" /> objects that will be copied to the destination table.</param>
<summary>Copies all rows from the supplied <see cref="T:System.Data.DataRow" /> array to a destination table specified by the <see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName" /> property of the <see cref="T:System.Data.SqlClient.SqlBulkCopy" /> object.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
While the bulk copy operation is in progress, the associated destination <xref:Microsoft.Data.SqlClient.SqlConnection> is busy serving it, and no other operations can be performed on the connection.
The <xref:Microsoft.Data.SqlClient.SqlBulkCopy.ColumnMappings> collection maps from the <xref:System.Data.DataRow> columns to the destination database table.
## Examples
The following console application demonstrates how to bulk load data from a <xref:System.Data.DataRow> array. The destination table is a table in the **AdventureWorks** database.
In this example, a <xref:System.Data.DataTable> is created at run time. A single row is selected from the <xref:System.Data.DataTable> to copy to the destination table.
> [!IMPORTANT]
> This sample will not run unless you have created the work tables as described in [Bulk Copy Example Setup](/sql/connect/ado-net/sql/bulk-copy-example-setup). This code is provided to demonstrate the syntax for using **SqlBulkCopy** only. If the source and destination tables are in the same SQL Server instance, it is easier and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data.
[!code-csharp[SqlBulkCopy.RowArray#1](~/../sqlclient/doc/samples/SqlBulkCopy_RowArray.cs#1)]
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">
A
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopyColumnOrderHint" />
did not specify a valid destination column name.
</exception>
</WriteToServer>
<WriteToServerAsync name="DataRowParameter">
<param name="rows">
An array of
<see cref="T:System.Data.DataRow" />
objects that will be copied to the destination table.
</param>
<summary>
The asynchronous version of
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer(System.Data.DataRow[])" />,
which copies all rows from the supplied
<see cref="T:System.Data.DataRow" />
array to a destination table specified by the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName" />
property of the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
object.
</summary>
<returns>
A task representing the asynchronous operation.
</returns>
<remarks>
<format type="text/markdown"><![CDATA[
For more information about asynchronous programming in the .NET Framework Data Provider for SQL Server, see [Asynchronous Programming](/sql/connect/ado-net/asynchronous-programming).
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">
Calling
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerAsync(System.Data.DataRow[])" />
multiple times for the same instance before task completion. Calling
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerAsync(System.Data.DataRow[])" />
and
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer(System.Data.DataRow[])" />
for the same instance before task completion.
The connection drops or is closed during
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerAsync(System.Data.DataRow[])" />
execution.
Returned in the task object, the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
object was closed during the method execution.
Returned in the task object, there was a connection pool timeout.
Returned in the task object, the
<see cref="T:Microsoft.Data.SqlClient.SqlConnection" />
object is closed before method execution.
A
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopyColumnOrderHint" />
did not specify a valid destination column name.
</exception>
<exception cref="T:Microsoft.Data.SqlClient.SqlException">
Returned in the task object, any error returned by SQL Server that occurred while opening the connection.
</exception>
</WriteToServerAsync>
<WriteToServerAsync name="DataRowAndCancellationTokenParameters">
<param name="rows">
An array of
<see cref="T:System.Data.DataRow" />
objects that will be copied to the destination table.
</param>
<param name="cancellationToken">
The cancellation instruction. A
<see cref="P:System.Threading.CancellationToken.None" />
value in this parameter makes this method equivalent to
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerAsync(System.Data.DataTable)" />.
</param>
<summary>
The asynchronous version of
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer(System.Data.DataRow[])" />,
which copies all rows from the supplied
<see cref="T:System.Data.DataRow" />
array to a destination table specified by the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName" />
property of the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
object.
The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object.
</summary>
<returns>
A task representing the asynchronous operation.
</returns>
<remarks>
<format type="text/markdown"><![CDATA[
For more information about asynchronous programming in the .NET Framework Data Provider for SQL Server, see [Asynchronous Programming](/sql/connect/ado-net/asynchronous-programming).
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">
Calling
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerAsync(System.Data.DataRow[])" />
multiple times for the same instance before task completion.
Calling
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerAsync(System.Data.DataRow[])" />
and
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer(System.Data.DataRow[])" />
for the same instance before task completion.
The connection drops or is closed during
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerAsync(System.Data.DataRow[])" />
execution.
Returned in the task object, the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
object was closed during the method execution.
Returned in the task object, there was a connection pool timeout.
Returned in the task object, the
<see cref="T:Microsoft.Data.SqlClient.SqlConnection" />
object is closed before method execution.
A
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopyColumnOrderHint" />
did not specify a valid destination column name.
</exception>
<exception cref="T:Microsoft.Data.SqlClient.SqlException">
Returned in the task object, any error returned by SQL Server that occurred while opening the connection.
</exception>
</WriteToServerAsync>
<WriteToServerAsync name="DbDataReaderParameter">
<param name="reader">
A
<see cref="T:System.Data.IDataReader" />
whose rows will be copied to the destination table.
</param>
<summary>
The asynchronous version of
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer(System.Data.IDataReader)" />,
which copies all rows in the supplied
<see cref="T:System.Data.IDataReader" />
to a destination table specified by the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName" />
property of the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
object.
</summary>
<returns>
A task representing the asynchronous operation.
</returns>
<remarks>
<format type="text/markdown"><![CDATA[
For more information about asynchronous programming in the .NET Framework Data Provider for SQL Server, see [Asynchronous Programming](/sql/connect/ado-net/asynchronous-programming).
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">
Calling
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerAsync(System.Data.IDataReader)" />
multiple times for the same instance before task completion.
Calling
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerAsync(System.Data.IDataReader)" />
and
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer(System.Data.IDataReader)" />
for the same instance before task completion.
The connection drops or is closed during
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerAsync(System.Data.IDataReader)" />
execution.
Returned in the task object, the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
object was closed during the method execution.
Returned in the task object, there was a connection pool timeout.
Returned in the task object, the
<see cref="T:Microsoft.Data.SqlClient.SqlConnection" />
object is closed before method execution.
The
<see cref="T:System.Data.IDataReader" />
was closed before the completed
<see cref="T:System.Threading.Tasks.Task" />
returned.
The
<see cref="T:System.Data.IDataReader" />'s associated connection was closed before the completed
<see cref="T:System.Threading.Tasks.Task" />
returned.
A
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopyColumnOrderHint" />
did not specify a valid destination column name.
</exception>
<exception cref="T:Microsoft.Data.SqlClient.SqlException">
Returned in the task object, any error returned by SQL Server that occurred while opening the connection.
</exception>
</WriteToServerAsync>
<WriteToServerAsync name="DbDataReaderAndCancellationTokenParameters">
<param name="reader">
A
<see cref="T:System.Data.Common.DbDataReader" />
whose rows will be copied to the destination table.
</param>
<param name="cancellationToken">
The cancellation instruction. A
<see cref="P:System.Threading.CancellationToken.None" />
value in this parameter makes this method equivalent to
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServerAsync(System.Data.Common.DbDataReader)" />.
</param>
<summary>
The asynchronous version of
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer(System.Data.Common.DbDataReader)" />,
which copies all rows from the supplied
<see cref="T:System.Data.Common.DbDataReader" />
array to a destination table specified by the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName" />
property of the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />
object.
The cancellation token can be used to request that the operation be abandoned before the command timeout elapses. Exceptions will be reported via the returned Task object.
</summary>
<returns>
A task representing the asynchronous operation.
</returns>
<remarks>
To be added.
</remarks>
</WriteToServerAsync>
<WriteToServerAsync name="IDataReaderParameter">
<param name="reader">
A
<see cref="T:System.Data.IDataReader" />
whose rows will be copied to the destination table.
</param>
<summary>
The asynchronous version of
<see cref="M:Microsoft.Data.SqlClient.SqlBulkCopy.WriteToServer(System.Data.IDataReader)" />,
which copies all rows in the supplied
<see cref="T:System.Data.IDataReader" />
to a destination table specified by the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.DestinationTableName" />
property of the
<see cref="T:Microsoft.Data.SqlClient.SqlBulkCopy" />