Can SQLBulkCopy be nested transaction?

HAN MING ONG 21 Reputation points
2023-03-31T10:23:58.24+00:00

Hi, I like to archieve a single transaction commit after running Project A update statement and Project B SQLBulkCopy. Is it possible for SQLBulkCopy to be nested inside Project A transaction? I have try pass in Project A SqlTransaction and use inside Project B SqlBulkCopy but encountered "The transaction is either not associated with the current connection or has been completed." is due to a new initialize of SQLConnection inside SQLBulkCopy?

Please advise

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,371 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,239 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 55,686 Reputation points
    2023-03-31T17:39:59.7933333+00:00

    they need to use the same connection (which is hard with EF) or be a common distributed transactions. see:

    https://learn.microsoft.com/en-us/ef/ef6/saving/transactions

    0 comments No comments