Skip to content
Advertisement

Stored procedure runs correctly only sometimes

My problem is: I have a stored procedure that only sometimes runs correctly, sometimes it does not run at all and sometimes partially (some rows where inserted in the table bot not all). I use lazarus 2.0.6 on Win10 64bit and a TODBCConnection to connect to SQL Server 2012.

The stored procedure itself is correct, in SQL Server Management Studio, it runs without problems. The stored procedure writes records into 4 different tables; depending on the parameters approximately 1-400 records per table.

The code:

If I set a breakpoint at qry.ExecSQL; and step over it – it works ?!

It seems that it doesn’t wait for qry.ExecSQL; to finish and frees the resources directly afterwards. What can I do to tell the code to wait until qry.ExecSQL; is finished?

Edit: the problem seems to be that qry.ExecSQL; runs asynchronous instead of synchronous as it should be. How can I tell this call to run synchronous?

Thanks in advance.

Advertisement

Answer

have it figured out: it´s a bug in sqldb.pas, in combination with odbc he can´t detect when a stored procedure is finished. so the programm immediatly steps to the next command, which in my case was the freeing of the database-instance -with the result that the sql-command was aborted. using now the “zeos” library (https://zeoslib.sourceforge.io) and it works like a charm.

the rest is identical to the old code, with one excaption: con.close(); becomes con.connected:=false;

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement