Skip to content

How to Retrieve the Native Handle of a TSQLConnection

Let’s say you want to share a connection to InterBase between IBX and dbExpress. For that you’ll need to retrieve the handle used by dbExpress and then use TIBDatabase.SetHandle to tell IBX to use that connection. But how to get the handle from dbExpress? Martijn Tonies pointed me in the right direction, and I wrote the following sample code:

procedure TForm1.Button1Click(Sender: TObject);
var
  SR: SQLResult;
  iHandle: Longint;
  iLen: SmallInt;
begin
  SQLConnection1.Connected := True;
  try
    SR := SQLConnection1.SQLConnection.GetOption(eConnNativeHandle, @iHandle, SizeOf(iHandle), iLen);
    if SR = DBXERR_NONE then begin
      ShowMessage('Handle: ' + IntToStr(iHandle));
    end else begin
      ShowMessage('Couldn''t retrieve native handle; error ' + IntToStr(SR));
    end; // if
  finally
    SQLConnection1.Connected := False;
  end; // if
end;

{ 2 } Comments

  1. andrew | September 20, 2006 at 12:33 pm | Permalink

    Cool!

    I have tried it myself before, but it didn’t work.

    But this works great! Thnx!

  2. Andrew | October 11, 2006 at 8:48 am | Permalink

    You must use dbExpInt.dcu in your project,

    is does not work with dbExpInt.dll!!!

    ———————————-

    uses

    Midaslib,

    Crtl,

    dbExpInt, //needed for sharing handle!

    ———————————-

Post a Comment

Your email is never published nor shared. Required fields are marked *

Bad Behavior has blocked 1846 access attempts in the last 7 days.

Close