SqlBulkCopy.WriteToServerAsync SqlBulkCopy.WriteToServerAsync SqlBulkCopy.WriteToServerAsync 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

WriteToServerAsync(IDataReader, CancellationToken) WriteToServerAsync(IDataReader, CancellationToken) WriteToServerAsync(IDataReader, CancellationToken)

The asynchronous version of WriteToServer(IDataReader), which copies all rows in the supplied IDataReader to a destination table specified by the DestinationTableName property of the 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.

WriteToServerAsync(DbDataReader) WriteToServerAsync(DbDataReader) WriteToServerAsync(DbDataReader) 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(DataRow[]) WriteToServerAsync(DataRow[]) WriteToServerAsync(DataRow[]) WriteToServerAsync(DataRow[])

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

WriteToServerAsync(DataTable) WriteToServerAsync(DataTable) WriteToServerAsync(DataTable) WriteToServerAsync(DataTable)

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

WriteToServerAsync(IDataReader) WriteToServerAsync(IDataReader) WriteToServerAsync(IDataReader) WriteToServerAsync(IDataReader)

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

WriteToServerAsync(DbDataReader, CancellationToken) WriteToServerAsync(DbDataReader, CancellationToken) 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.

WriteToServerAsync(DataRow[], CancellationToken) WriteToServerAsync(DataRow[], CancellationToken) WriteToServerAsync(DataRow[], CancellationToken)

The asynchronous version of WriteToServer(DataRow[]), which copies all rows from the supplied DataRow array to a destination table specified by the DestinationTableName property of the 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.

WriteToServerAsync(DataTable, DataRowState) WriteToServerAsync(DataTable, DataRowState) WriteToServerAsync(DataTable, DataRowState) WriteToServerAsync(DataTable, DataRowState)

The asynchronous version of WriteToServer(DataTable, DataRowState), which copies only rows that match the supplied row state in the supplied DataTable to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

WriteToServerAsync(DataTable, CancellationToken) WriteToServerAsync(DataTable, CancellationToken) WriteToServerAsync(DataTable, CancellationToken)

The asynchronous version of WriteToServer(DataTable), which copies all rows in the supplied DataTable to a destination table specified by the DestinationTableName property of the 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.

WriteToServerAsync(DataTable, DataRowState, CancellationToken) WriteToServerAsync(DataTable, DataRowState, CancellationToken) WriteToServerAsync(DataTable, DataRowState, CancellationToken)

The asynchronous version of WriteToServer(DataTable, DataRowState), which copies only rows that match the supplied row state in the supplied DataTable to a destination table specified by the DestinationTableName property of the 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.

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(IDataReader, CancellationToken) WriteToServerAsync(IDataReader, CancellationToken) WriteToServerAsync(IDataReader, CancellationToken)

The asynchronous version of WriteToServer(IDataReader), which copies all rows in the supplied IDataReader to a destination table specified by the DestinationTableName property of the 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.

public:
 System::Threading::Tasks::Task ^ WriteToServerAsync(System::Data::IDataReader ^ reader, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task WriteToServerAsync (System.Data.IDataReader reader, System.Threading.CancellationToken cancellationToken);
member this.WriteToServerAsync : System.Data.IDataReader * System.Threading.CancellationToken -> System.Threading.Tasks.Task

Parameters

reader
IDataReader IDataReader IDataReader IDataReader

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

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

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

Returns

A task representing the asynchronous operation.

Exceptions

Calling WriteToServerAsync(IDataReader) multiple times for the same instance before task completion.

Calling WriteToServerAsync(IDataReader) and WriteToServer(IDataReader) for the same instance before task completion.

The connection drops or is closed during WriteToServerAsync(IDataReader) execution.

Returned in the task object, the 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 SqlConnection object is closed before method execution.

The IDataReader was closed before the completed Task returned.

The IDataReader's associated connection was closed before the completed Task returned.

Context Connection=true is specified in the connection string.

Returned in the task object, any error returned by SQL Server that occurred while opening the connection.

Remarks

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

WriteToServerAsync(DbDataReader) WriteToServerAsync(DbDataReader) WriteToServerAsync(DbDataReader) 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.

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 DbDataReader DbDataReader DbDataReader

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

Returns

A task representing the asynchronous operation.

WriteToServerAsync(DataRow[]) WriteToServerAsync(DataRow[]) WriteToServerAsync(DataRow[]) WriteToServerAsync(DataRow[])

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

public:
 System::Threading::Tasks::Task ^ WriteToServerAsync(cli::array <System::Data::DataRow ^> ^ rows);
public System.Threading.Tasks.Task WriteToServerAsync (System.Data.DataRow[] rows);
member this.WriteToServerAsync : System.Data.DataRow[] -> System.Threading.Tasks.Task
Public Function WriteToServerAsync (rows As DataRow()) As Task

Parameters

rows
DataRow[]

An array of DataRow objects that will be copied to the destination table.

Returns

A task representing the asynchronous operation.

Exceptions

Calling WriteToServerAsync(DataRow[]) multiple times for the same instance before task completion.

Calling WriteToServerAsync(DataRow[]) and WriteToServer(DataRow[]) for the same instance before task completion.

The connection drops or is closed during WriteToServerAsync(DataRow[]) execution.

Returned in the task object, the 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 SqlConnection object is closed before method execution.

Context Connection=true is specified in the connection string.

Returned in the task object, any error returned by SQL Server that occurred while opening the connection.

Remarks

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

WriteToServerAsync(DataTable) WriteToServerAsync(DataTable) WriteToServerAsync(DataTable) WriteToServerAsync(DataTable)

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

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

Parameters

table
DataTable DataTable DataTable DataTable

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

Returns

A task representing the asynchronous operation.

Exceptions

Calling WriteToServerAsync(DataTable) multiple times for the same instance before task completion.

Calling WriteToServerAsync(DataTable) and WriteToServer(DataTable) for the same instance before task completion.

The connection drops or is closed during WriteToServerAsync(DataTable) execution.

Returned in the task object, the 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 SqlConnection object is closed before method execution.

Context Connection=true is specified in the connection string.

Returned in the task object, any error returned by SQL Server that occurred while opening the connection.

Remarks

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

WriteToServerAsync(IDataReader) WriteToServerAsync(IDataReader) WriteToServerAsync(IDataReader) WriteToServerAsync(IDataReader)

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

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

Parameters

reader
IDataReader IDataReader IDataReader IDataReader

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

Returns

A task representing the asynchronous operation.

Exceptions

Calling WriteToServerAsync(IDataReader) multiple times for the same instance before task completion.

Calling WriteToServerAsync(IDataReader) and WriteToServer(IDataReader) for the same instance before task completion.

The connection drops or is closed during WriteToServerAsync(IDataReader) execution.

Returned in the task object, the 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 SqlConnection object is closed before method execution.

The IDataReader was closed before the completed Task returned.

The IDataReader's associated connection was closed before the completed Task returned.

Context Connection=true is specified in the connection string.

Returned in the task object, any error returned by SQL Server that occurred while opening the connection.

Remarks

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

WriteToServerAsync(DbDataReader, CancellationToken) WriteToServerAsync(DbDataReader, CancellationToken) 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.

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

Parameters

reader
DbDataReader DbDataReader DbDataReader DbDataReader

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

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

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

Returns

Returns Task.

WriteToServerAsync(DataRow[], CancellationToken) WriteToServerAsync(DataRow[], CancellationToken) WriteToServerAsync(DataRow[], CancellationToken)

The asynchronous version of WriteToServer(DataRow[]), which copies all rows from the supplied DataRow array to a destination table specified by the DestinationTableName property of the 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.

public:
 System::Threading::Tasks::Task ^ WriteToServerAsync(cli::array <System::Data::DataRow ^> ^ rows, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task WriteToServerAsync (System.Data.DataRow[] rows, System.Threading.CancellationToken cancellationToken);
member this.WriteToServerAsync : System.Data.DataRow[] * System.Threading.CancellationToken -> System.Threading.Tasks.Task

Parameters

rows
DataRow[]

An array of DataRow objects that will be copied to the destination table.

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

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

Returns

A task representing the asynchronous operation.

Exceptions

Calling WriteToServerAsync(DataRow[]) multiple times for the same instance before task completion.

Calling WriteToServerAsync(DataRow[]) and WriteToServer(DataRow[]) for the same instance before task completion.

The connection drops or is closed during WriteToServerAsync(DataRow[]) execution.

Returned in the task object, the 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 SqlConnection object is closed before method execution.

Context Connection=true is specified in the connection string.

Returned in the task object, any error returned by SQL Server that occurred while opening the connection.

Remarks

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

WriteToServerAsync(DataTable, DataRowState) WriteToServerAsync(DataTable, DataRowState) WriteToServerAsync(DataTable, DataRowState) WriteToServerAsync(DataTable, DataRowState)

The asynchronous version of WriteToServer(DataTable, DataRowState), which copies only rows that match the supplied row state in the supplied DataTable to a destination table specified by the DestinationTableName property of the SqlBulkCopy object.

public:
 System::Threading::Tasks::Task ^ WriteToServerAsync(System::Data::DataTable ^ table, System::Data::DataRowState rowState);
public System.Threading.Tasks.Task WriteToServerAsync (System.Data.DataTable table, System.Data.DataRowState rowState);
member this.WriteToServerAsync : System.Data.DataTable * System.Data.DataRowState -> System.Threading.Tasks.Task
Public Function WriteToServerAsync (table As DataTable, rowState As DataRowState) As Task

Parameters

table
DataTable DataTable DataTable DataTable

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

rowState
DataRowState DataRowState DataRowState DataRowState

A value from the DataRowState enumeration. Only rows matching the row state are copied to the destination.

Returns

A task representing the asynchronous operation.

Exceptions

Calling WriteToServerAsync(DataTable, DataRowState) multiple times for the same instance before task completion.

Calling WriteToServerAsync(DataTable, DataRowState) and WriteToServer(DataTable, DataRowState) for the same instance before task completion.

The connection drops or is closed during WriteToServerAsync(DataTable, DataRowState) execution.

Returned in the task object, the 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 SqlConnection object is closed before method execution.

Context Connection=true is specified in the connection string.

Returned in the task object, any error returned by SQL Server that occurred while opening the connection.

Remarks

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

WriteToServerAsync(DataTable, CancellationToken) WriteToServerAsync(DataTable, CancellationToken) WriteToServerAsync(DataTable, CancellationToken)

The asynchronous version of WriteToServer(DataTable), which copies all rows in the supplied DataTable to a destination table specified by the DestinationTableName property of the 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.

public:
 System::Threading::Tasks::Task ^ WriteToServerAsync(System::Data::DataTable ^ table, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task WriteToServerAsync (System.Data.DataTable table, System.Threading.CancellationToken cancellationToken);
member this.WriteToServerAsync : System.Data.DataTable * System.Threading.CancellationToken -> System.Threading.Tasks.Task

Parameters

table
DataTable DataTable DataTable DataTable

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

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

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

Returns

A task representing the asynchronous operation.

Exceptions

Calling WriteToServerAsync(DataTable) multiple times for the same instance before task completion.

Calling WriteToServerAsync(DataTable) and WriteToServer(DataTable) for the same instance before task completion.

The connection drops or is closed during WriteToServerAsync(DataTable) execution.

Returned in the task object, the 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 SqlConnection object is closed before method execution.

Context Connection=true is specified in the connection string.

Returned in the task object, any error returned by SQL Server that occurred while opening the connection.

Remarks

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

WriteToServerAsync(DataTable, DataRowState, CancellationToken) WriteToServerAsync(DataTable, DataRowState, CancellationToken) WriteToServerAsync(DataTable, DataRowState, CancellationToken)

The asynchronous version of WriteToServer(DataTable, DataRowState), which copies only rows that match the supplied row state in the supplied DataTable to a destination table specified by the DestinationTableName property of the 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.

public:
 System::Threading::Tasks::Task ^ WriteToServerAsync(System::Data::DataTable ^ table, System::Data::DataRowState rowState, System::Threading::CancellationToken cancellationToken);
public System.Threading.Tasks.Task WriteToServerAsync (System.Data.DataTable table, System.Data.DataRowState rowState, System.Threading.CancellationToken cancellationToken);
member this.WriteToServerAsync : System.Data.DataTable * System.Data.DataRowState * System.Threading.CancellationToken -> System.Threading.Tasks.Task

Parameters

table
DataTable DataTable DataTable DataTable

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

rowState
DataRowState DataRowState DataRowState DataRowState

A value from the DataRowState enumeration. Only rows matching the row state are copied to the destination.

cancellationToken
CancellationToken CancellationToken CancellationToken CancellationToken

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

Returns

A task representing the asynchronous operation.

Exceptions

Calling WriteToServerAsync(DataTable, DataRowState) multiple times for the same instance before task completion.

Calling WriteToServerAsync(DataTable, DataRowState) and WriteToServer(DataTable, DataRowState) for the same instance before task completion.

The connection drops or is closed during WriteToServerAsync(DataTable, DataRowState) execution.

Returned in the task object, the 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 SqlConnection object is closed before method execution.

Context Connection=true is specified in the connection string.

Returned in the task object, any error returned by SQL Server that occurred while opening the connection.

Remarks

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

Applies to