Subject Re: [IBO] StoredProc Error
Author Helen Borrie (TeamIBO)
At 02:41 PM 15-03-02 -0800, you wrote:
>I have just started using IBObjects and have a problem running a stored
>I have a proc defined in the database as so
>create procedure nextidaddress
>returns (NEXTID integer)
> NextID = GEN_ID(AddressGen, 1);
> suspend;
> exit;
>which runs fine. Im trying to call it through code by issuing -
> FStoredProc.IB_Connection := FDataTarget;
> FStoredProc.StoredProcName := AProcName;
> FStoredProc.ParamNames.Clear;
> FStoredProc.Prepare;
> FStoredProc.ExecProc;
> Result := FStoredProc.FieldByName('NEXTID').AsInteger;
> FStoredProc.Unprepare;
> FStoredProc.IB_Transaction.Commit;
>But when I do I keep getting 'Invalid Transaction handle (expecting explicit
>transaction start)' at the Prepare statement which I thought was because I
>havent issued an FStoreProc.StartTransaction, even if I add this line of

StartTransaction is a method of a transaction, not of a stored
procedure. This code could be corrected like this:

with FStoredProc do
IB_Connection := FDataTarget;
if not IB_Connection.Connected then
StoredProcName := AProcName;
if not IB_Transaction.TransactionIsActive then
Params[0].Value := something;
Params[1].Value := somethingelse;
Result := FieldByName('NEXTID').AsInteger;
if Prepared then Unprepare;

However, there is no need to have your own procedure to do any of
this. Either set the GeneratorLinks in the dataset that wants the
generated value, or call the Gen_ID() method of either the dataset or the

Either (GeneratorLinks property)

or (if you want to do something with the value before the Insert is posted):

MyDataset.FieldByName('Somefile').AsInteger := MyDataset.GEN_ID(AddressGen, 1);

Helen Borrie (TeamIBO Support)

** Please don't email your support questions privately **
Ask on the list and everyone benefits
Don't forget the IB Objects online FAQ - link from any page at