Recent

Author Topic: Firebird: how to tell if the database is running.  (Read 11472 times)

JD

  • Hero Member
  • *****
  • Posts: 1758
Re: Firebird: how to tell if the database is running.
« Reply #15 on: April 27, 2013, 04:23:41 pm »
If you want to know if the Firebird Server is running, you can use the code at the following website http://www.chami.com/tips/delphi/031498D.html

Before I try to connect to the database, I test to know if the Firebird server is running using the code below

Code: [Select]
  { Test for Firebird embedded, server and client installations }
  if FileExistsUTF8(ExtractFilePath(Application.ExeName) + 'fbclientd.dll') then
  begin
    strProtocolType := 'firebirdd-2.5';     // Firebird Embedded 2.1.3+
    frmMainform.strServerType := 'firebird embedded';
    UsesFirebirdEmbeddedServer := True;
  end
  else
  begin
    strProtocolType := 'firebird-2.5';     // Firebird Client or Server 2.1.3+
    if ServiceRunning('', 'FirebirdServerDefaultInstance') then        // Localhost
      frmMainform.strServerType := 'firebird server'
    else
      frmMainform.strServerType := 'firebird client';
    UsesFirebirdEmbeddedServer := False;
  end;

ServiceRunning is one of the functions at the website whose link is given above. Of course, this works only on Windows. I've never tried it on Linux BUT I would welcome any tips on how to test to see if Firebird server is running on Linux.

Hope it helps,

JD

Windows (10, 7) - Lazarus 2.0RC3/FPC 3.2, NewPascal, Delphi

Indy 10.6 series; mORMot; Zeos 7.2.1; SQLite, Firebird, PostgreSQL & MariaDB; VirtualTreeView 5.5.3 R1

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Firebird: how to tell if the database is running.
« Reply #16 on: April 27, 2013, 04:43:57 pm »
Nice approach to query the Windows service - though I suspect you can start the FB server manually, too. I'd therefore rather use taskmanager (or the API equivalents with FPC)
Edit:
http://wiki.lazarus.freepascal.org/Windows_Programming_Tips#Showing.2Ffinding_processes

I've never tried it on Linux BUT I would welcome any tips on how to test to see if Firebird server is running on Linux.
http://www.firebirdfaq.org/faq123/

:)
« Last Edit: April 27, 2013, 04:49:49 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

cov

  • Full Member
  • ***
  • Posts: 222
Re: Firebird: how to tell if the database is running.
« Reply #17 on: April 27, 2013, 04:58:52 pm »
As Big Chimp correctly surmised, an error had crept into my code (I freed a dynamic form too early), so the error which came up was nothing to do with the fact that Firebird wasn't running and, although the GDB stopped my code at point where the IBDConnect component connected, running the executable on it's own allowed the exception to be caught correctly.

I hear what you're saying about the snippets of code.

Although the project isn't exactly top secret, I'd be a little peeved if a more competent programmer managed to put a product on the market which does what my app is supposed to do (and probably did it better).

I have, in the past, put together half-projects to demonstrate where some code was misbehaving and would have done so again, had your suggestion to look elsewhere not borne fruit.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Firebird: how to tell if the database is running.
« Reply #18 on: April 27, 2013, 05:37:00 pm »
Good - glad it's solved ;)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified