IBCServerProperties example?

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
kneighbour
Posts: 77
Joined: Wed 08 Oct 2008 04:55

IBCServerProperties example?

Post by kneighbour » Tue 10 Feb 2015 04:51

I would like to see the users connected to a Firebird server. I am guessing that the IBCServerProperties will show me this, but I cannot work out how to use it.

I can run this SQL "SELECT * FROM MON$ATTACHMENTS" using IBExpert (to the exact same Firebird server) and I get the results I want. ie the users that are connected, the process name, IP address, etc. Just perfect.

I try to run the same SQL using UniDac and I get only 1 record returned. I am using a Classic server, so this is perhaps understandable. It is a bit puzzling that both SQL Maestro and IBExpert both give the correct (multiple record) results.

I am hoping that IBCServerProperties will give me more correct results.

Note : the fields I am particularly looking at are
MON$REMOTE_PROCESS
MON$REMOTE_ADDRESS
MON$ATTACHMENT_NAME

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: IBCServerProperties example?

Post by ViktorV » Wed 11 Feb 2015 08:53

You can get all the needed information about the TIBCServerProperties class in the IBDAC documentation: http://www.devart.com/ibdac/docs/devart ... embers.htm
Unfortunately, we can't reproduce the issue in the way you have described it. The specified query in UniDAC returns correct data.
The problem may occur when attempting to update data of the open dataset. When updating the dataset, try to explicitly commit the transaction and reopen the dataset:

Code: Select all

  if UniQuery.Transaction.Active then
    UniQuery.Transaction.Commit;
  UniQuery.Open;
instead of

Code: Select all

  UniQuery.Refresh

kneighbour
Posts: 77
Joined: Wed 08 Oct 2008 04:55

Re: IBCServerProperties example?

Post by kneighbour » Thu 12 Feb 2015 10:58

Not sure what the comments on the transaction are supposed to mean? I can only assume that you were meant to be talking to someone else?

The IBDAC documentation lists the properties/methods of TIBCServerProperties, but frankly it is of little help.

I can call ServerProperties.FetchDatabaseInfo; How does that help me? Where do I list out the various properties? What is the syntax? How do I list out (for example)
MON$REMOTE_PROCESS
MON$REMOTE_ADDRESS
MON$ATTACHMENT_NAME
??

Actually, I tried to call FetchDatabaseInfo, but I could not get it to work. I got an error message about not being able to connect to the service. Do you have any example code where you use this component?

Since I cannot work out how to use TIBCServerProperties, I tried a standard UniDAC UniQuery and ran the SQL "SELECT * FROM MON$ATTACHMENTS". This returns exactly the data I want - but only 1 record. If I run the exact same SQL using other tools (ie IBExpert), then I get the correct number of records returned. ie not 1.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: IBCServerProperties example?

Post by ViktorV » Thu 12 Feb 2015 12:38

The issue may be in the user account you are using to connect to the database with UniDAC.
Using MON$ATTACHMENTS, only SYSDBA and the database owner can view information about all the connections. Ordinary users can view only information about their connections.

kneighbour
Posts: 77
Joined: Wed 08 Oct 2008 04:55

Re: IBCServerProperties example?

Post by kneighbour » Thu 12 Feb 2015 22:49

Fair enough. I only use one user - SYSDBA - on all of my databases.

kneighbour
Posts: 77
Joined: Wed 08 Oct 2008 04:55

Re: IBCServerProperties example?

Post by kneighbour » Thu 12 Feb 2015 23:30

Done a bit more testing. The UniQuery approach (using SQL) works to some extent.

You MUST disconnect the UniConnection before the calling the query (and then connect again).

It only shows the connections to the database file the UniConnection is connected to. This is good enough.

Be nice to get the IBCServerProperties to work though.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: IBCServerProperties example?

Post by ViktorV » Fri 13 Feb 2015 09:53

Instead of reopening connection to the server, you can explicitly commit the transaction and reopen UniQuery:

Code: Select all

  if UniQuery.Transaction.Active then
    UniQuery.Transaction.Commit;
  UniQuery.Open;
Please run the following code after setting the correct values: Server, Port, Username, Password, Database. And check whether the problem is reproduced on it. If an error occurs during execution, please provide its full text.

Code: Select all

program TestServerProperties;

{$APPTYPE CONSOLE}

uses
  System.SysUtils, IBCAdmin;

var
  IBCServerProperties: TIBCServerProperties;
  i: Integer;
  DBNameList: String;

begin
  IBCServerProperties := TIBCServerProperties.Create(nil);
  try
    IBCServerProperties.Server := Server;
    IBCServerProperties.Port := Port;
    IBCServerProperties.ClientLibrary := ClientLibrary;
    IBCServerProperties.Username := Username;
    IBCServerProperties.Password := Password;
    if not IBCServerProperties.Active then
      IBCServerProperties.Attach;
    IBCServerProperties.FetchDatabaseInfo;
    if IBCServerProperties.DatabaseInfo.NoOfAttachments > 0 then begin
      DBNameList := 'Databases names: ';
      for i := 0 to IBCServerProperties.DatabaseInfo.NoOfDatabases - 1 do
        DBnameList := DBNameList +  
          IBCServerProperties.DatabaseInfo.DbName[i] + '. ';
      WriteLn(DBNameList + #$D#$A + 'Number of attachments: ' +
        IntToStr(IBCServerProperties.DatabaseInfo.NoOfAttachments) + #$D#$A +
        'Number of databases: ' + 
        IntToStr(IBCServerProperties.DatabaseInfo.NoOfDatabases));
      end
      else
        WriteLn('No info.');
    IBCServerProperties.Detach;
    ReadLn;
  finally
    IBCServerProperties.Free;
  end;
end.

Post Reply