Subject Re: How to find a transaction in the code given TID?
Author Thomas
Hi Krzysztof,

> I am using TIBClientDataSet, TIBQuery and TIBSQL for
> changing the DB content. Do these components have any access to the
> Transaction IDs which is being created while these are
opened/executed?

No they do not have a method but its quite easy to write one to get
the transaction id, here is the one I use when getting "stuck
transaction" issues. Please note that this is not the most optimised
function if you're going to call it all the time, we have a form that
displays all the currently open transactions by looping though
TIBDatabase.Transactions and calling this function to get the
transaction id and then displaying that with the transaction
component's name and all the queries connected to it, it is normally
quite easy to find the problem area. A "better" method if you've got
lots of method users like we do and it is not practical to go though
each user's terminal to figure out where the stuck transaction is to
write a new IGDSLibrary that inherits from the existing on and add
code to the IGDSLibrary.isc_start_multiple write the id of the
transaction and the component information to a log file that you can
then retrieve from all the machines and do a search though to find
the offending transaction.

function GetTransactionID(IBTransaction: TIBTransaction): Integer;
var
iLength: Integer;
result_buffer: array[0..31] of char;
TransactionInfoCommand: Char;
LocalHandle: TISC_TR_HANDLE;
LocalGDSLibrary: IGDSLibrary;
isc_transaction_info: Tisc_transaction_info;
hIBLibrary: THandle;
begin
Result := 0;
if IBTransaction.InTransaction then
begin
//Get the currently loaded library
LocalGDSLibrary := GetGDSLibrary;

//Load a new instance of the library since they do not
//expose the handle of the current library
hIBLibrary := LoadLibrary(PChar(IBASE_DLL));
if (hIBLibrary > HINSTANCE_ERROR) then
begin
try
//Try to get an address to the function else raise an error
isc_transaction_info := GetProcAddress(
hIBLibrary, 'isc_transaction_info' );
if not Assigned( isc_transaction_info ) then
RaiseLastOSError;

LocalHandle := IBTransaction.Handle;
TransactionInfoCommand := Char(isc_info_tra_id);
isc_transaction_info( StatusVector, @LocalHandle, 1,
@TransactionInfoCommand, 32, result_buffer );
iLength := LocalGDSLibrary.isc_vax_integer( @result_buffer
[1], 2 );
Result := LocalGDSLibrary.isc_vax_integer( @result_buffer[3],
iLength );
finally
FreeLibrary( hIBLibrary );
end;
end;
end;
end;

Regards
Thomas Ellis