Rediger

SqlBulkCopy.WriteToServerAsync Method

Definition

An asynchronous version of WriteToServer, which copies all rows from a data source to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

Overloads

Name Description
WriteToServerAsync(DbDataReader)

The asynchronous version of WriteToServer(DbDataReader), which copies all rows from the supplied DbDataReader array to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

WriteToServerAsync(DbDataReader, CancellationToken)

The asynchronous version of WriteToServer(DbDataReader), which copies all rows from the supplied DbDataReader array to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

Remarks

If multiple active result sets (MARS) is disabled, WriteToServer makes the connection busy. If MARS is enabled, you can interleave calls to WriteToServer with other commands in the same connection.

The number of rows that are rolled back when one fails depends on several things:

When there is an error while sending data to the server, the current batch (as specified by BatchSize) will be rolled back. If UseInternalTransaction is not specified and you have your own transaction, the entire transaction will be rolled back (which includes all previous batches as well).

Use SqlRowsCopied to know how many rows were copied to the server.

WriteToServerAsync(DbDataReader)

Source:
System.Data.SqlClient.notsupported.cs

The asynchronous version of WriteToServer(DbDataReader), which copies all rows from the supplied DbDataReader array to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

public:
 System::Threading::Tasks::Task ^ WriteToServerAsync(System::Data::Common::DbDataReader ^ reader);
public System.Threading.Tasks.Task WriteToServerAsync(System.Data.Common.DbDataReader reader);
member this.WriteToServerAsync : System.Data.Common.DbDataReader -> System.Threading.Tasks.Task
Public Function WriteToServerAsync (reader As DbDataReader) As Task

Parameters

reader
DbDataReader

A DbDataReader whose rows will be copied to the destination table.

Returns

A task representing the asynchronous operation.

Remarks

For more information about asynchronous programming in the .NET Framework Data Provider for SQL Server, see Asynchronous Programming.

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by WriteToServer(DbDataReader).

Applies to

WriteToServerAsync(DbDataReader, CancellationToken)

Source:
System.Data.SqlClient.notsupported.cs

The asynchronous version of WriteToServer(DbDataReader), which copies all rows from the supplied DbDataReader array to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

public:
 System::Threading::Tasks::Task ^ WriteToServerAsync(System::Data::Common::DbDataReader ^ reader, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task WriteToServerAsync(System.Data.Common.DbDataReader reader, System.Threading.CancellationToken cancellationToken);
member this.WriteToServerAsync : System.Data.Common.DbDataReader * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Function WriteToServerAsync (reader As DbDataReader, cancellationToken As CancellationToken) As Task

Parameters

reader
DbDataReader

A DbDataReader whose rows will be copied to the destination table.

cancellationToken
CancellationToken

The cancellation instruction. A None value in this parameter makes this method equivalent to WriteToServerAsync(DbDataReader).

Returns

Returns Task.

Exceptions

The cancellation token was canceled. This exception is stored into the returned task.

Remarks

This method stores in the task it returns all non-usage exceptions that the method's synchronous counterpart can throw. If an exception is stored into the returned task, that exception will be thrown when the task is awaited. Usage exceptions, such as ArgumentException, are still thrown synchronously. For the stored exceptions, see the exceptions thrown by WriteToServer(DbDataReader).

Applies to