dotnet / dotnet/docs

docs of using transactions with sqlbulkcopy is internally contradictory

Open
#19,953 8 comments 0 reactions 1 assignee Claimed by @stevestein View on GitHub
data-access/subsvc dotnet-framework/svc waiting-on-feedback
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
19h 10m
Merged PRs (30d)
268

Description

**Issue description**
[This document](https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/transaction-and-bulk-copy-operations) claims that _**Performing a Dedicated Bulk Copy Operation in a Transaction**_ is similar to _**Performing a Non-transacted Bulk Copy Operation**_ with one exception!

The problem is that they are no difference between them in terms of how they handle a failure.
According to docs, **if no transaction is used**:
> All batches copied up to the point of the error are committed; the batch containing the duplicate key is rolled back, and the bulk copy operation is halted before processing any other batches. (quoted from the _Performing a Non-transacted Bulk Copy Operation_ section)

and again according to docs, if `UseInternalTransaction` flag is used in order to perform a transacted bulk copy, the same behavior is happening:
> l batches copied up to the point of the error are committed; the batch containing the duplicate key is rolled back, and the bulk copy operation is halted before processing any other batches. (quoted from the _Performing a Dedicated Bulk Copy Operation in a Transaction_ section)

How are they different?

On the other hand the first paragraph of document says that:
> The bulk copy operation occurs in a non-transacted way, with no opportunity for rolling it back.

and then suggests that if you need to rollback part of it, you need to use a transaction. In contrast of this, later in this article, it is stated that batches are executed in their own transaction, when we are "Performing a Non-transacted Bulk Copy Operation",and if a problem occurs the batch containing the problematic row will rollback!

**Target framework**

Check the .NET target framework(s) being used, and include the version number(s).

- [ X] .NET Core
- [X ] .NET Framework
- [ ] .NET Standard

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.