Transactions from TransactionScope to Sql Compact Edition 3.5

I have a question. I am developing a small desktop application in win Forms. I am using SQL CE 3.5 SP1 for the database.

When I do inserts on multiple tables in several ways, I use TansactionScope. When I use only these methods, I want to use a normal transaction from a database connection.

Is there any way to check the called method if the database binding is now in the transaction area?

The answer to sending this information to a method that is not very good, in the future we will change the implementation of SQL Ce to plain SQL, and then I will not change the implementation, so this is not a good idea.

The solution was before I used ADO in every transaction, but it was wrong because there was transactionScope outside that did not roll back this transition. I decided to delete all ADO transactions, and then the rollback was fine, so I don't know when I can use ADO and when not ...

+3
source share
1 answer

I'm not sure that they will work in Compact Edition 3.5, but this is what other versions of SQL Server use:

XACT_STATE () reports on the transaction status of the session, indicating whether the session has an active transaction and whether the transaction can be completed. It returns three values:

  • 1, . , .
  • 0, .
  • -1, , , , . ; . - , . , . , , .

@@TRANCOUNT .

  • 0,
  • 1,
  • n,

. :

SELECT
    *
    FROM sys.dm_tran_session_transactions
    WHERE session_id=@@SPID

:

SELECT
    *
    FROM sys.dm_tran_session_transactions             s
        INNER JOIN sys.dm_tran_active_transactions    a On s.transaction_id=a.transaction_id
    WHERE s.session_id=@@SPID
+2

Source: https://habr.com/ru/post/1718058/


All Articles