MS SQL Server and BEGIN TRANSACTION

Having a weird issue with MS SQL Server. I’m trying to create a transaction and I’ve verified that I’ve started the transaction with

db.SQLExecute( “BEGIN TRANSACTION” )

but then when I got to commit I get the following error: The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.

I’ve verified that I’m not calling BEGIN TRANSACTION more than once but it is getting called with no errors.

Anyone have suggestions on things to look at?

almost sounds like its already been committed so you end up having a commit with the begin

but I’m sure you’ve looked into that already

Yeah. This is in ActiveRecord and not having any issues with any of the other databases - just MS SQL Server.

Begin Transaction didn’t happen to fail did it ?
Its been a few years but I can’t imagine what else unless you’ve nested them or used something like begin transaction with a named transaction the commit without closing a named one
There’s only a handful of reasons this should occur

Never used MS SQL Server, but may be some kind of autocommit?.

Unlikely if you have explicitly started one
Oh but there is one option… are you using ODBC ?
You’ll love this one if you are …
see
https://technet.microsoft.com/en-us/library/ms175127(v=sql.105).aspx
where it says
The ODBC API does not support explicit transactions, only autocommit and implicit transactions.

No, definitely not ODBC. This is native SQL Server.

OK that rules that out

Hmmm … begin isn’t failing somehow ?
I’m out of ideas as to why it might give you that on a commit

I will end up breaking it down into something uber simple first. If I can replicate it that way then it’s simple enough to send in for the engineers to look at. Otherwise it will prove that’s it’s something with ActiveRecord and the real fun begins.

You can use

Exec sp_who2

See if you can find the begin transaction and then see if the other statements are on the same spid

This has come up again in this Forum Thread (which I think has an answer and a workaround).