I am having some confusion with set chained
statement in setAutoCommit()
method in net.sourceforge.jtds.jdbc.Driver
The source code says:
2161 if (serverType == Driver.SYBASE) {
2162 if (autoCommit) {
2163 sql.append("SET CHAINED OFF");
2164 } else {
2165 sql.append("SET CHAINED ON");
2166 }
However, shouldn't it be backwards, and chaining should be OFF for autoCommit==false?
The reason I ran into this is as follows:
I am writing a Java app which needs to do some complicated SQL and roll back all of it if any of it fails:
Open Sybase connection using
net.sourceforge.jtds.jdbc.Driver
Call setAutoCommit(false)
Do SQL1
Call stored proc 'MySP1'
Stored proc MySP1' is NOT under my control
It has
EXEC sp_procxmode 'dbo.MySP1','unchained'
Do SQL2
If SQL2 fails, roll back everything (including SQL1), otherwise commit.
Having done that, I get the following error from MySP1:
Stored procedure 'MySP1' may be run only in unchained transaction mode. The 'SET CHAINED OFF' command will cause the current session to use unchained transaction mode.