begin tran
insert into OPENDATASOURCE ('SQLOLEDB','Data Source=psserver;User ID=sa;Password=').test.DBO.T_tests (F_speccode,F_specname,F_sprice,F_type) 
select F_speccode,F_specname,F_sprice,F_type from T_spec
insert into T_bookc(F_bookcode,F_speccode,F_num) 
select F_Bookcode,F_Bookspeccode,F_nums from T_books
if @@error=0
begin
 update T_spec set F_state=1 
 commit tran
end
else
begin 
 rollback tran
end
go在查询分析器里执行以上语句时提示
“无法为 OLE DB 提供程序 'SQLOLEDB' 启动嵌套事务。之所以需要嵌套事务是因为 XACT_ABORT 选项已设置为 OFF。
[OLE/DB provider returned message: 无法在此会话中启动更多的事务。]”本意是将表T_spec中的记录插入到表T_tests ,表T_books插入到表T_bookc,如果两个表都插入成功,则把T_spec中的字段F_state改为1,否则则回滚!
请各位大哥帮忙看看!

解决方案 »

  1.   

    T_tests ,T_bookc在服务Psserver上
      

  2.   

    SET XACT_ABORT ON 
    begin tran
    insert into OPENDATASOURCE ('SQLOLEDB','Data Source=psserver;User ID=sa;Password=').test.DBO.T_tests (F_speccode,F_specname,F_sprice,F_type) 
    select F_speccode,F_specname,F_sprice,F_type from T_spec
    insert into T_bookc(F_bookcode,F_speccode,F_num) 
    select F_Bookcode,F_Bookspeccode,F_nums from T_books
    if @@error=0
    begin
     update T_spec set F_state=1 
     commit tran
    end
    else
    begin 
     rollback tran
    end
    SET XACT_ABORT off
    go
      

  3.   

    to itblog:设置了SET XACT_ABORT ON ,事务应该会自动回滚。应该不用写rollback tran了吧
      

  4.   

    SET XACT_ABORT ON 
    begin tran
     insert into OPENDATASOURCE ('SQLOLEDB','Data   Source=psserver;User ID=sa;Password=').test.DBO.T_tests  (F_speccode,F_specname,F_sprice,F_type) 
     select F_speccode,F_specname,F_sprice,F_type from T_spec
      insert into T_bookc(F_bookcode,F_speccode,F_num) 
      select F_Bookcode,F_Bookspeccode,F_nums from T_books
      update T_spec set F_state=1 
    commit tran
    SET XACT_ABORT OFF
    -----
    另外if @@error=0只能判断最近一条语句的执行状态