IB7.1 Number of users logged into the DB, and who they are.

Posted on 2003-11-01
Last Modified: 2013-12-09
Interbase 7.1
Delphi 7
Looking for a code sample on how to determine the number of users currently logged into a specific database (not just the server).  Any other supporting logon information would also be helpful.   Do not want to give the users SYSDBA access to get this information.   This information is to be used to control the number of valid users within an application.
Question by:chart11610
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Assisted Solution

BAlexandrov earned 100 total points
ID: 9809876
I have done this one time  - it was for puprose to be able to view whish users are currently connected. The application itself had users - a table with information about each user but without the password.
When new user is created - it creates new user on the server also with the suffix - application name.
When user logon - it is authenticated to the server(user name that he have supplied + application name and the password) - with logging in to the database.
Then it is easy to get list of currently active users on the server, filter this list with users only from our application (comparing with the users table in our database) and list only them.

Drawbacks - you have to include in your app hidden administrative password - an account that will have rights to make new servers accounts.

Just as example..

Bojidar Alexandrov
LVL 19

Accepted Solution

Gary Benade earned 150 total points
ID: 9865086
below is a function to retrieve the usernames into a StringList using the Interbase API.
I am actually a c programmer so I may have made some syntax errors.

procedure TForm1.GetConnStats( FUserNames: TStringList)

db_handle: isc_db_handle;
DPB_Buffer: array [0..255] of Char;
DPB_Index: Integer;
DBName_Cstr: array [0..255] of Char;
temp_buffer: array[0..255] of Char;

{Options buffer and index}

DBStatOpts: array [0..15] of Byte;
NumOpts: Integer;

{Result buffer array, index and pointer}

Result_Buffer: array [0..1023] of Byte;
RB_index: Integer;
RB_ptr: Pointer;

{Variables for handling each return item}
Item: Byte;
ItemLen: ISC_LONG;
Page_Size: Longint;
Num_Pages: Longint;
i, user_length: Integer;


{Initialise the buffer index and set the first character value which is always the parameter buffer version number}
DPB_Index := 0;
DPB_Buffer[DPB_Index] := Char(isc_dpb_version1);

{Set the user name parameter identifier and copy the name from the user name edit field on the form}
DPB_Buffer[DPB_Index] := Char(isc_dpb_user_name);
DPB_Buffer[DPB_Index] := Char(Length(Edit_Username.Text));
StrPCopy(@DPB_Buffer[DPB_Index], Edit_Username.Text);
Inc(DPB_Index, Length(Edit_Username.Text));

{Set the password parameter identifier and copy the name from the password edit field on the form}
DPB_Buffer[DPB_Index] := Char(isc_dpb_password);
DPB_Buffer[DPB_Index] := Char(Length(Edit_Password.Text));
StrPCopy(@DPB_Buffer[DPB_Index], Edit_Password.Text);
Inc(DPB_Index, Length(Edit_Password.Text));

{Copy the database name from the edit field on the form to a C-string style character array}
StrPCopy(DBName_Cstr, Edit_DBName.Text);

{Initialise the database handle to nil - mandatory}
db_handle := nil;

{Attach to the database}
isc_attach_database(@Status_Vector, Length(Edit_DBName.Text), @DBName_Cstr, @db_handle, DPB_Index, DPB_Buffer);

{ Username extraction starts here }

{Exit if we’re not connected}
if db_handle = nil then

{Set up the information options required}
NumOpts := 0;
DBStatOpts[NumOpts] := isc_info_page_size;
DBStatOpts[NumOpts] := isc_info_allocation;

{Issue the call to get the information required about usernames}
if isc_database_info (@Status_Vector, @db_handle, NumOpts, @DBStatOpts, SizeOf(Result_Buffer), @Result_Buffer) <> 0 then

RB_Index := 0;

while Result_Buffer[RB_Index] = Char(isc_info_user_names)
Inc(RB_Index, 3); { skip "isc_info_user_names byte" & two unknown bytes of structure}
user_length := Long(Result_Buffer[RB_Index]);
Move(Result_Buffer[RB_Index], temp_buffer[0], user_length);
Inc(RB_Index, user_length);  
temp_buffer[user_length] := #0;
end; { while }

{ Username extraction section ends here }

{Detach to the database}
if db_handle <> nil then isc_detach_database( @Status_Vector, @db_handle);


Expert Comment

ID: 9866114
Great job, hobbit72!
But this can be done via ibx components (or other)...
The main problem is that this is list of users connected to the _server_. To _any_ database on this server.
The problem is how to get users connected only to your application's own database.

Bojidar Alexandrov
LVL 10

Expert Comment

ID: 10340582
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:
      to split points between BAlexandrov (100) and hobbit72 (150)
Please leave any comments here within the next four (4) days.


If you will get a useful answer to your newer question next time, please accept it after evaluating. By this way the experts will get sooner his expert points for supporting you. If you have question about, please look at

EE Cleanup Volunteer

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Query help 3 78
CentOS Backup Options 3 66
databases from multiple applications - same instance 6 40
comparing two rows 10 40
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question