Skip to content
GitLab
    • Why GitLab
    • Pricing
    • Contact Sales
    • Explore
  • Why GitLab
  • Pricing
  • Contact Sales
  • Explore
  • Sign in
  • Get free trial
  • FPC
  • LazarusLazarus
  • LazarusLazarus
  • Issues
  • #40151

Firebird connect / diconnect more times error connection shutdown

  • Lazarus/FPC Version: Lazarus 2.2.4 (rev lazarus_2_2_4) FPC 3.2.2 x86_64-win64-win32/win64
  • Operating System: Windows or Macos
  • CPU / Bitness: 64bit

What happens

using the sqldb components to connect to the Firebird (TSQLConnector) if you connect the first time it's fine, if you disconnect and then retry a connection you get the following error:

connection shutdown

after several searches the problem, in my opinion, is in the following piece of code in file ibase60.inc:

Procedure ReleaseIBase60;
 
begin
  if RefCount>1 then
    Dec(RefCount)
  else
    begin
    // Shutdown embedded subsystem with timeout 300ms (Firebird 2.5+)
    // Required before unloading library; has no effect on non-embedded client
    if (pointer(fb_shutdown)<>nil) and (fb_shutdown(300,1)<>0) then
      begin
      //todo: log error; still try to unload library below as the timeout may have been insufficient
      end;
    if UnloadLibrary(LibHandle) then
      begin
      Dec(RefCount);
      LibHandle := NilHandle;
      LoadedLibrary:='';
      end;
    end;
end;

calling fb_shutdown creates problems for non-embedded databases

Procedure ReleaseIBase60;
 
begin
  if RefCount>1 then
    Dec(RefCount)
  else
    begin
    If UseEmbeddedFirebird then
      begin
      // Shutdown embedded subsystem with timeout 300ms (Firebird 2.5+)
      // Required before unloading library; has no effect on non-embedded client
      if (pointer(fb_shutdown)<>nil) and (fb_shutdown(300,1)<>0) then
        begin
        //todo: log error; still try to unload library below as the timeout may have been insufficient
        end;
      end;
    if UnloadLibrary(LibHandle) then
      begin
      Dec(RefCount);
      LibHandle := NilHandle;
      LoadedLibrary:='';
      end;
    end;
end;  

Steps to reproduce

Insert TSQLConnector in a form, setting Firebird ConnectoryType, setting database,password and username and connect to true. After disconnect and reconnect.

Assignee
Assign to
Time tracking