Subject Re: [IBO] Getting number of active users via MON$ATTACHMENTS?
Author Chuck Belanger
What I did that works:

Create IB_Cursor as query, create Connection and Transaction, all of
which are Freed/nil at end of routine.

Also, the SELECT itself does not include Mon$State, because by limiting
to state = 1, I missed inactive connections.

I added DISTINCT to Mon$Remote_Processes and that worked to get what I
needed.

The whole point of this is to fire an alert (a timer checks for
connections every 10 seconds) for a user who is acting as the DB server
for a shared database in an office connected through the router.  I am
trying to reduce the possibility that he/she accidentally shuts down the
shared server (a laptop) before any other user is done being connected.

The program is a desktop program where on occasion we have users who
want to share patients records while in the office.

I am aware and we are doing our best to educate the users that this is
not the best way to do this and they need to develop habits to avoid
cutting off the server before another person is done using it.

I have found that with ethernet connection to the local router, this is
a very fast connection. Wifi less so.

HTH,

Chuck

On 1/3/2019 8:59 AM, Chuck Belanger phytotech@... [IBObjects] wrote:
> Thank you, Carlos.
>
> The Qry I use is created for each call of the routine (done by a timer).
> I added the IB_Transaction.commit. And still I am not getting the
> correct results. Now I get 1 when I should have 2 and likewise there is
> no change as I disconnect from the database (in IBExpert).  Still
> getting those crazy large Mon$Attachment_IDs, too.
>
> I still suspect that having falsely high IDs means something. As a test
> I have a "do while not eof" and look at the
> FieldByNAme('mon$attachment_id).asInt64. That is when I notice the 10 to
> the 17th power IDs. Like I said they actually are 4 digits long now.
>
> Any other thoughts?
>
> Chuck
>
> On 1/3/2019 7:53 AM, 'Carlos H. Cantu' listas@...
> [IBObjects] wrote:
>> You need to commit the transaction associated to that IB_Cursor to get
>> "fresh" values from the monitoring tables, otherwise, it will always
>> return the same information, since a snapshot of the monitoring data
>> is taken when you run the select for the first time.
>>
>> []s
>> Carlos H. Cantu
>> eBook Guia de Migração para o FB 3 - www.firebase.com.br/guiafb3.php
>> www.FireBase.com.br - www.firebirdnews.org - blog.firebase.com.br
>>
>> CBplcI> Hello:
>>
>> CBplcI> How do we get the number of active users with IBO?
>>
>> CBplcI> I tried to simply use a IB_Cursor with:
>>
>> CBplcI> SELECT * FROM MON$ATTACHMENTS WHERE MON$STATE = 1
>>
>> CBplcI> But if I connected or disconnected from the database via IBExpert, the
>> CBplcI> count stays the same. Although, querying in IBExpert gives the correct
>> CBplcI> number of active connections, i.e. 2, one for my program and one for
>> CBplcI> IBExpert.
>>
>> CBplcI> As I experimented with different approaches, I noticed something that
>> CBplcI> might be a clue:
>>
>> CBplcI> When I checked the MON$ATTACHMENT_ID in my code it was always the same
>> CBplcI> from record to record and consistently up around 10x17th power, although
>> CBplcI> different from one query to another. The actual IDs are 4 digits long,
>> CBplcI> and of course, different for each record.
>>
>> CBplcI> Tried using IB_Connection.Users.Count but that includes all active and
>> CBplcI> inactive users. I could not find a way to isolate only active users.
>>
>> CBplcI> Thank you for any help or suggestions!
>>
>> CBplcI> Chuck Belanger
>>
>>
>> CBplcI> ---
>> CBplcI> This email has been checked for viruses by Avast antivirus software.
>> CBplcI> https://www.avast.com/antivirus
>>
>>
>>
>> CBplcI> ------------------------------------
>> CBplcI> Posted by: Chuck Belanger <phytotech@...>
>> CBplcI> ------------------------------------
>>
>> CBplcI> ___________________________________________________________________________
>> CBplcI> IB Objects - direct, complete, custom connectivity to Firebird or InterBase
>> CBplcI> without the need for BDE, ODBC or any other layer.
>> CBplcI> ___________________________________________________________________________
>> CBplcI> http://www.ibobjects.com - your IBO community resource for Tech Info papers,
>> CBplcI> keyword-searchable FAQ, community code contributions and more !
>> CBplcI> http://tracker.ibobjects.com - your portal to submit and monitor bug reports
>> CBplcI> http://community.ibobjects.com - your portal to purchase and upgrade
>> CBplcI> ------------------------------------
>>
>> CBplcI> Yahoo Groups Links
>>
>>
>>
>>
>>
>> ------------------------------------
>> Posted by: "Carlos H. Cantu" <ibo@...>
>> ------------------------------------
>>
>> ___________________________________________________________________________
>> IB Objects - direct, complete, custom connectivity to Firebird or InterBase
>> without the need for BDE, ODBC or any other layer.
>> ___________________________________________________________________________
>> http://www.ibobjects.com - your IBO community resource for Tech Info papers,
>> keyword-searchable FAQ, community code contributions and more !
>> http://tracker.ibobjects.com - your portal to submit and monitor bug reports
>> http://community.ibobjects.com - your portal to purchase and upgrade
>> ------------------------------------
>>
>> Yahoo Groups Links
>>
>>
>>
>>
>
> ------------------------------------
> Posted by: Chuck Belanger <phytotech@...>
> ------------------------------------
>
> ___________________________________________________________________________
> IB Objects - direct, complete, custom connectivity to Firebird or InterBase
> without the need for BDE, ODBC or any other layer.
> ___________________________________________________________________________
> http://www.ibobjects.com - your IBO community resource for Tech Info papers,
> keyword-searchable FAQ, community code contributions and more !
> http://tracker.ibobjects.com - your portal to submit and monitor bug reports
> http://community.ibobjects.com - your portal to purchase and upgrade
> ------------------------------------
>
> Yahoo Groups Links
>
>
>
>