Yesterday I spent many hours reading the dozens of posts on the subject, written by Bob Keeney, Norman Palardy, Jay Madren, Scott Cadillac and many others, but I have not found the solution (maybe I’m going blind?)
I am writing an application in Xojo 2019r1.1, Windows 10 environment, SQL Server Express database.
I have to perform multiple updates to three tables, and for each table I have a class that does all what is needed.
My idea is to perform a BEGIN TRANSACTION at the beginning, try the various updates and, in case one of these updates fails, perform a ROLLBACK and stop processing.
When all the updates are successful I COMMIT the transaction.
But it happens what reported by Bob: the ROLLBACK is not successful (error “The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.”)
I tried to connect to the database with both the ODBC driver and the Plugin, but the situation is the same.
I’ve made many unsuccessful attempts in the past.
Finally, I decided to use transactions within MSSQL stored procedures.
Since then, I have no longer this problem.
Note: I use the MBS plugin, but I think even the Xojo plugin allows you to run a stored procedure.
Did you try to use BEGIN TRANSACTION, ROLLBACK and COMMIT outside a stored procedure, using the MBS Plugin?
Does it work?
If it works, that is my solution.
But if it works only in a stored procedure, this makes me rewrite almost everything (and I don’t want it)
I just remember it never well worked.
maybe for my mistakes, maybe not.
besides, the use of stored procedures allows me to avoid complex queries in the Xojo project.
using the RDBMS native features.
Norman, I have just tried today to use MBS plugin, but it seems to me that the problem is still here.
But perhaps I don’t know much about MBS Plugin, and I am doing something wrong.
How do you deal with Begin Transaction, Rollback and Commit?
Do they work? Could you show a piece of code,?
Thanks a lot.
MBS has basically 3 API’s which makes it confusing
I’m afraid I cant share as this is a client project that I cant share things from (patents and such)
The second SQL statement is wrong because the column OFR_NUMEROzz is not present in the table.
But the line DB.Rollback does not work, because “there is no a corresponding BEGIN TRANSACTION”
I tried setting IMPLICIT_TRANSACTIONS OFF before and after the BEGIN TRANSACTION, I tried with SET ANSI_DEFAULTS OFF, but everything I do leads always to the same.
With MBS Xojo SQL Plugin and either SQLDatabaseMBS or SQLConnectionMBS you should only need to set AutoCommit property to kAutoCommitOff, which should implicit start a new transaction. Do your calls and make a Commit call on the end.
But this is up to the different connectors in the plugin how they implement it.
You know, we support 15 database types including 3 ways to talk to MSSQL.
The Xojo plugin for MSSQL has been a pain in the *** as long as I know. Never got fixed.
I would suggest: just don’t distribute it if you know it doesn’t work properly.
Lot’s of us wasted time on it which could have been prevented if pointed into the right direction straight away.
Like most programming languages, also Xojo has its pitfalls and it helps if you know where they are.
Hi Joost, coming from Visual Basic and working on Windows environment, SQL Server is my standard Database for many years now.
When I switch to Xojo I had some troubles with MSSQL plugin, so I usually prefer the ODBC driver.
As far as you know, does the ODBC driver for SQL Server work fine or there are issues with it?