SQLConnection: There is no Active Transaction

Delphi

24/08/2010

Bom dia,

No meu sistema quando estou gravando a venda ele já inclui o contas a receber se estiver parcelado em mais de duas parcelas o sistema da o seguinte erro: "SQLConnection: There is no Active Transaction", não estou conseguindo encontrar o que pode estar ocasionando esse erro, alguem poderia me ajudar, já procurei aqui no Forum e não encontrei.

Desde já agradeço a ajuda de todos.
George Medeiros

George Medeiros

Curtidas 0

Respostas

Marco Salles

Marco Salles

24/08/2010

aparentemente vc esta num Loop   Um erro encontrado   aborta a transação   porém vc continua no Loop   depois tenta comita-la , porém esta ja não existe mais   Coloque o seu codigo   informe tb qual odelphi
GOSTEI 0
George Medeiros

George Medeiros

24/08/2010

O código que uso para inserir a venda e o contas a receber é esse:

procedure TDM.InsereVenda;
var
  idvenda :Integer;
begin
  idvenda := 0;
  Start;
  try
    with  spIUVenda do
    begin
      Params[0].AsInteger := cdsVendaID_VENDA.AsInteger;
      Params[1].AsInteger := cdsVendaID_FUNCIONARIO.AsInteger;
      Params[2].AsInteger := cdsVendaID_CLIENTE.AsInteger;
      Params[3].AsInteger := cdsVendaID_PLANOPAGAMENTO.AsInteger;
      Params[4].AsInteger := cdsVendaID_FORMAPAGAMENTO.AsInteger;
      Params[5].AsInteger := cdsVendaID_ORCAMENTO.AsInteger;
      Params[6].AsBCD     := cdsVendaDESCONTOPERC.AsCurrency;
      Params[7].AsBCD     := cdsVendaVL_DESCONTO.AsCurrency;
      Params[8].AsBCD     := cdsVendaVL_TOTAL.AsCurrency;
      Params[9].AsDate    := cdsVendaDT_VENDA.AsDateTime;
      Params[10].AsString := cdsVendaNUMNF.AsString;
      Params[11].AsString := cdsVendaTEMORCAMENTO.AsString;
      ExecProc;
      Comit;
      idvenda := Params[12].AsInteger;
    end;
  except
    Rollback;
  end;

  //Insere Item
  Start;
  try
    cdsItemVenda.First;
    while not cdsItemVenda.Eof do
    begin
      with spIUItemVenda do
      begin
        Params[0].AsInteger := cdsItemVendaID_ITEMVENDA.AsInteger;
        Params[1].AsInteger := idvenda;
        Params[2].AsInteger := cdsItemVendaID_PRODUTO.AsInteger;
        Params[3].AsBCD     := cdsItemVendaQUANTIDADE.AsCurrency;
        Params[4].AsBCD     := cdsItemVendaVL_UNIT.AsCurrency;
        Params[5].AsBCD     := cdsItemVendaDESCONTOPERC.AsCurrency;
        Params[6].AsBCD     := cdsItemVendaVL_DESCONTO.AsCurrency;
        Params[7].AsBCD     := cdsItemVendaVL_TOTAL.AsCurrency;
        ExecProc;
      end;
      DiminuiQuantidade(1,1, cdsItemVendaID_PRODUTO.AsInteger, cdsItemVendaQUANTIDADE.AsCurrency);
      cdsItemVenda.Next;
    end;
  except
    Rollback;
    DeletaVenda(idvenda, 'N');
  end;

  //insere contas a receber
  Start;
  try
    cdsContaReceder.First;
    while not cdsContaReceder.Eof do
    begin
      with spIUContaReceber do
      begin
        Params[0].AsInteger := cdsContaRecederID_CONTARECEBER.AsInteger;
        Params[1].AsInteger := cdsContaRecederID_EMPRESA.AsInteger;
        Params[2].AsInteger := cdsContaRecederID_CLIENTE.AsInteger;
        Params[3].AsInteger := cdsContaRecederID_CENTROCUSTO.AsInteger;
        Params[4].AsInteger := cdsContaRecederID_FORMAPAGAMENTO.AsInteger;
        Params[5].AsInteger := cdsContaRecederID_FUNCIONARIO.AsInteger;
        Params[6].AsInteger := idvenda;
        Params[7].AsString := cdsContaRecederNUMDOC.AsString;
        Params[8].AsDate := cdsContaRecederDT_EMISSAO.AsDateTime;
        Params[9].AsDate := cdsContaRecederDT_VENCIMENTO.AsDateTime;
        Params[10].AsBCD := cdsContaRecederVALOR.AsCurrency;
        Params[11].AsBCD := 0.00;
        Params[12].AsBCD := 0.00;
        Params[13].AsBCD := 0.00;
        Params[14].AsBCD := 0.00;
        Params[15].AsString := 'A';
        ExecProc;
        Comit;
      end;
      cdsContaReceder.Next;
    end;
  except
    Rollback;
    DeletaVenda(idvenda, 'N');
  end;
end;
GOSTEI 0
George Medeiros

George Medeiros

24/08/2010

Uso o Delphi 7.
GOSTEI 0
Marco Salles

Marco Salles

24/08/2010

bem eu entendo que transação é uma atomicidade   Seria mais ou menos assim   Inicia a Transação //codigo para Inserir Venda //codigo para Inserir Item //codigo para inserir Contas a Recebe Comit  ... Um so Comit para as Tres operaçoes except Roolback .. Um so Roolback para as Tres operaçoes   De modo que vc tenha uma ATomicidade .. Ou Tudo da Certo ou nada feito
GOSTEI 0
George Medeiros

George Medeiros

24/08/2010

Marcos Antonio, obrigado deu certo dessa forma que você falou.
GOSTEI 0
POSTAR