Search code examples
delphifirebirddbexpressdelphi-6

How can I get the name of the database a DBExpress TSqlConnection is actually connected to?


I'm testing a quite old Delphi 6 application and would like to display the database name the TSqlConnection is actually connected to, so I can see quickly if I'm connected to the test or production database.

In sqlconnections.ini, the app has a connection named 'Vienna' to a Firebird database defined like this: Database=192.168.1.15:ProductionDB (it's an alias) and I've replaced that for testing purposes with Database=192.168.1.15:TestDB.

But I've seen that just accessing the TSqlConnection's Params-List and there the value of 'Database' does not work. This value is always set the same as it is in design mode.

How can I find out which database (which Firebird alias in my case) the TSqlConnection is actually connected to?


Solution

  • monitoring tables were introduced into FB 2.1.x :-)

    So try

     select MON$DATABASE_NAME from MON$DATABASE
    

    Or try

     select MON$ATTACHMENT_NAME from MON$ATTACHMENTS
        where MON$ATTACHMENT_ID = CURRENT_CONNECTION
    

    See info at