1. Marc James
  2. PowerBuilder
  3. Thursday, 5 March 2020 15:11 PM UTC

Hello,

What is the best method to keep a count of users logged into your application, handling things like the user crashing out and still keeping count etc, then locking people logging in based on that count.

Thanks

mike S Accepted Answer Pending Moderation
  1. Thursday, 5 March 2020 15:33 PM UTC
  2. PowerBuilder
  3. # 1

it depends on how you connect to your database, and what your database is.

If you only use a single connection in your application per exe, and set an application id along with your connection, then you can utilize your database's information to see how many logins are currently connected.

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Thursday, 5 March 2020 15:44 PM UTC
  2. PowerBuilder
  3. # 2

Depending on your database you should be able to form a query that is a variation on the sp_who stored procedure. Set the AppName in the DBParm and then use that in the where clause.

Comment
  1. Chris Pollach @Appeon
  2. Friday, 6 March 2020 17:06 PM UTC
Great idea Roland ... I also include the "Host" ID as well (if DBMS supports it). For example:

SQLCA.DBParm = "Async=1,DBGetTime=5,DBTextLimit='90000',TrimSpaces=0,AppName='PB2019R2',Host='STD-Chris'"

Most DBMS then have an Logon SP (or allow you to build your own) that is called by the DBMS itself when a Connect; command is processed. So in that SP, you can track the DB Connections by App or Workstation (user).

  1. Helpful
There are no comments made yet.
Marc James Accepted Answer Pending Moderation
  1. Thursday, 5 March 2020 16:04 PM UTC
  2. PowerBuilder
  3. # 3

Yes, use SQL Anywhere 16 at the moment, we have an always opened connection
sqlca.DBMS = "ODBC"
CONNECT using sqlca;
Open throughout the application until close.
Should we DISCONNECT using sqlca; after we make SELECT/UPDATE etc or is it fine to just keep the connection open throughout, and is that required to be able to then count the users.

Comment
  1. mike S
  2. Thursday, 5 March 2020 16:31 PM UTC
sql anywhere - use sa_conn_info and connection property for this sort of info



select userid , CONNECTION_PROPERTY('Name', Number) AS program_name,

from sa_conn_info()



you have to be connected to the dbms to get the dbms info. get it, count the users, then disconnect if you are over the count.



  1. Helpful
There are no comments made yet.
David Peace Accepted Answer Pending Moderation
  1. Thursday, 5 March 2020 16:09 PM UTC
  2. PowerBuilder
  3. # 4

We add the application name to the database envionment details after connection. This allows us to select a count of active connections and use that to control user licensing.

Trying to manage counts in the database or something similar is problemmatic as you say when a program crashes out. In addition to the count in the DB you could create a file in the local user temp and delete it when the app closes. When the app opens you check for this file and that tells you they crashed out so you can ignore their new connection from a count poit of view. I would also reset the count for each working day to be sure.

Hope that helps

David

Comment
  1. Michael Kramer
  2. Thursday, 5 March 2020 20:04 PM UTC
You may include app version in the AppName. I've used that to deny/terminate connections from outdated app versions after database upgrades.
  1. Helpful
  1. Olan Knight
  2. Friday, 6 March 2020 00:35 AM UTC
Using the database is the way to go.

As long as the app is running, you can

- CHECK the number of users new user connects

- VERIFY that you have or have not hit the max number of users, and

- ALLOW or DENY access.

If you allow access you can yupdate the count to connected users.



The problem arises when the app crashes.

To get around this, I would add a LAST_TIME_VALIDATED column to be associated with the USER_ID in the list of active connections. I'd set a time and have the app update the LAST_TIME_VALIDATED once every couple of minutes; every 5 minutes, perhaps.

Each time auser wants to connect, check the LAST_TIME_VALIDATED, and if that value is more than 5 minutes out of date then the app crashed and you can replease that user with the one attempting to connect.



Olan
  1. Helpful
  1. David Peace (Powersoft)
  2. Friday, 6 March 2020 09:01 AM UTC
I like that idea Olan, neat and tidy :)

Michael we us ethe version numer too to check the app version connecting. Thisis done in the logon trigger in the DB and kicks the user off :)
  1. Helpful
There are no comments made yet.
Chris Keating Accepted Answer Pending Moderation
  1. Friday, 6 March 2020 03:14 AM UTC
  2. PowerBuilder
  3. # 5

Mark

 

You should look at the SQL Anywhere CREATE LOGIN POLICY functionality. 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.