我对 set chained
声明中 setAutoCommit()
方法中 net.sourceforge.jtds.jdbc.Driver
该 源码 说。
2161 if (serverType == Driver.SYBASE) {
2162 if (autoCommit) {
2163 sql.append("SET CHAINED OFF");
2164 } else {
2165 sql.append("SET CHAINED ON");
2166 }
然而, 是不是应该倒过来,autoCommit==false的链路应该是OFF?
我遇到这个问题的原因如下。
我正在写一个Java应用,它需要做一些复杂的SQL,并且在任何一个失败的情况下回滚所有的SQL。
打开Sybase连接,使用 net.sourceforge.jtds.jdbc.Driver
调用setAutoCommit(false)
做SQL1
调用存储的程序'MySP1'。
存储的proc MySP1'不在我的控制之下。
它有 EXEC sp_procxmode 'dbo.MySP1','unchained'
做SQL2
如果SQL2失败,则回滚一切(包括SQL1),否则提交。
这样做了之后,我从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.
我遇到了几乎同样的问题,通过运行下面的SQL解决了这个问题,希望能帮到你。
sp_procxmode your_stored_Procedure, 'anymode'
在你的例子中 your_stored_Procedure = MySP1 那么你应该运行以下代码。
sp_procxmode MySP1, 'anymode'
以防有人在7年后再来这里找你。
我通过以下方式让它发挥作用
connection.setAutoCommit(false); // this is mandatory, as without it jTDS will commit each statement.
在java中,并显式执行SQL代码。
SET CHAINED OFF
begin transaction