Breyta

Deila með


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)

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)

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[])

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)

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)

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)

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)

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)

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)

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)

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)

Source:
System.Data.SqlClient.notsupported.cs

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
Public Function WriteToServerAsync (reader As IDataReader, cancellationToken As CancellationToken) As Task

Parameters

reader
IDataReader

A IDataReader 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(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.

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

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(IDataReader).

Applies to

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

Source:
System.Data.SqlClient.notsupported.cs

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.

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

Applies to

WriteToServerAsync(DataTable)

Source:
System.Data.SqlClient.notsupported.cs

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

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.

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(DataTable).

Applies to

WriteToServerAsync(IDataReader)

Source:
System.Data.SqlClient.notsupported.cs

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

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.

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(IDataReader).

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

WriteToServerAsync(DataRow[], CancellationToken)

Source:
System.Data.SqlClient.notsupported.cs

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
Public Function WriteToServerAsync (rows As DataRow(), cancellationToken As CancellationToken) As Task

Parameters

rows
DataRow[]

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

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.

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

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

Applies to

WriteToServerAsync(DataTable, DataRowState)

Source:
System.Data.SqlClient.notsupported.cs

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

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

rowState
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.

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(DataTable, DataRowState).

Applies to

WriteToServerAsync(DataTable, CancellationToken)

Source:
System.Data.SqlClient.notsupported.cs

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
Public Function WriteToServerAsync (table As DataTable, cancellationToken As CancellationToken) As Task

Parameters

table
DataTable

A DataTable 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(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.

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

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(DataTable).

Applies to

WriteToServerAsync(DataTable, DataRowState, CancellationToken)

Source:
System.Data.SqlClient.notsupported.cs

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
Public Function WriteToServerAsync (table As DataTable, rowState As DataRowState, cancellationToken As CancellationToken) As Task

Parameters

table
DataTable

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

rowState
DataRowState

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

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.

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

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(DataTable, DataRowState).

Applies to