• Welcome to SQLitening Support Forum.
 

News:

Welcome to the SQLitening support forums!

Main Menu

List of users connected to a database ?

Started by Jean-Pierre LEROY, November 19, 2016, 02:49:09 PM

Previous topic - Next topic

Jean-Pierre LEROY

Dear all,

I know the slGetStatus(2) function which returns all connections to the SQLitening server.

I would like to know if someone has created a new function to retrieve the connections to a specific database ?

What I need is the list of users which are currently connected to the database.

Thanks,
Jean-Pierre


cj

#1
I haven't, but adding a logon table might be like this
I'm sure somebody has a table that does this.
This is just brainstorming and the table would probably be searched to see if user is allowed, already in, etc ...


#INCLUDE "sqlitening.inc"
%DoIt=0

FUNCTION PBMAIN () AS LONG
  LOCAL sIp AS STRING,sDatabase,sInsert AS STRING, PortNum AS LONG

  sIp = "192.168.0.6"
  portNum = 51234
  sDatabase = "sample.db3"

  IF %Doit THEN slconnect sIp,PortNum
  IF %DoIt THEN slopen sDatabase
  GOSUB LogOn
  IF %DoIt THEN slDisconnect
  EXIT FUNCTION
LogOn:
  IF %Doit THEN slexe "create table if not exists UserTable(Ip,Port,Database,LogOn,LogOff)"
  sInsert = "Insert into UserTable values('#IP','#Port','#Database','#LogOn','#LogOff')"
  REPLACE "#IP" WITH sIP IN sInsert
  REPLACE "#Port" WITH FORMAT$(PortNum) IN sInsert
  REPLACE "#Database" WITH sDatabase IN sInsert
  REPLACE "#LogOn" WITH TIME$ IN sInsert
  REPLACE "#LogOff" WITH "-" IN sInsert
  ? sInsert
  IF %DoIt THEN slExe sInsert
RETURN
END FUNCTION


Jean-Pierre LEROY

Hi,

Thank you for your answer.

This workaround should work fine obviously but the only drawback is that the programmer has to manage it.

I was asking myself if SQLitening was not updating internally a system table like this when an slOpen is issued?

Regards,
Jean-Pierre

cj

Need to think about this some more.
Entries easy to put in sqliteningserver.log

sqliteningserver.bas
LogIt 12345, sAnything



Bern Ertl

I built a user management system (log in/log out) that works like so:
  • Application has a master table/db that holds user accounts, passwords and active connection handle
  • SQLitening server exits ( SQLiteningServerExits.BAS ) clear the connection handles when SQLitening starts or a user disconnects
  • Application manages connection handle when a user is trying to log in (checks it to ensure user isn't already logged in, sets it when user successfully logs in)
  • Administrator account has ability to manage user database and kill/log out any connected users
The same concept could be adapted to also track to which database they are currently connected.