Performing Atomic SqlBulkCopy
Imports
To perform atomic
other database statements) we need to use transactions. The following steps outline the
process of using a transaction with
SqlBulkCopy
imports that span across all batches (and, optionally, across other database statements) we need to use transactions. The following steps outline the
process of using a transaction with
SqlBulkCopy
: - Create a SqlConnection to the destination database server.
- Open the connection.
- Create a
SqlTransaction
object. - Create the
SqlBulkCopy
object passing in theSqlTransaction
object into the constructor. - Perform the import - the call to
WriteToServer
- within aTry
...Catch
block. - If the operation completes, commit the transaction; if it fails, roll it back.
' STEP 1 - Create a SqlConnection to the destination database server |
If you had other statements that needed to be performed under the umbrella of this
transaction you would execute them within the Try
...Catch
block.
No comments :
Post a Comment