开发者

Suppress transaction in stored procedure

开发者 https://www.devze.com 2023-01-16 04:21 出处:网络
I want to know wether or not it is possible to suppress a transaction inside a SQL stor开发者_如何学JAVAed procedure. I have the following situation in my SP (that I want to achieve):

I want to know wether or not it is possible to suppress a transaction inside a SQL stor开发者_如何学JAVAed procedure. I have the following situation in my SP (that I want to achieve):

WHILE TRUE
BEGIN TRY
    BEGIN TRANSACTION A
    RECEIVE MESSAGE FROM SSB QUEUE WITH TIMEOUT

    BEGIN SUPPRESS TRANSACTION 
      WHILE RECORD IN TABLE
         BEGIN TRANSACTION B
           DELETE RECORD FROM TABLE OUTPUT RECORD INTO D
           SEND RECORD D TO OTHER SSB QUEUE
         COMMIT TRANSACTION B
    END SUPPRESS TRANSACTION
    COMMIT TRANSACTION A
END TRY
BEGIN CATCH
    ROLLBACK TRANSACTION A
END CATCH

so what I really want to do is that transaction B does not get enlisted in transaction A :)


You're describing an "autonomous transaction", which is a common question from people migrating from Oracle (which supports them) to MSSQL (which doesn't). This article explains the various options, which unfortunately aren't particularly attractive:

  1. A loopback linked server
  2. A loopback connection from a CLR procedure
  3. A table variable that stores the data, because they are not affected by rollbacks
  4. A loopback connection from an extended stored procedure (but they are deprecated anyway in favour of CLR procedures)

If none of those options are practical for you, the other alternative is to shift some control into an application and out of the database, but of course that just shifts the issue to another location. Still, it may be worth considering.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号