AutoProSoftwareUK
asked on
Counting Users logged into Access DataBase in Delphi
Hi. I have converted some BDE files (Paradox) into an Access MDB and I used to have a procedure which counted the number of users logged into an application
by cloning cursors and using the BDE function "Check(DbiIsRecordLocked(T able.Handl e, Locked))". This always worked great when users logged in and out, even if users crashed their OS.
I have searched about and came up with the code from Microsoft which uses OpenSchema with a SchemID which seems to not work (which I modified below).
I also checked some code which reads the LDB file, which I also have problems with as it is difficult to read this file, and anyway I dont feel its safe.
Anyone done this in Delphi already?
My test is like this so far (trying to load details into a memo), I guess I must not be understanding something :-))
I have 4 objects on a form: ADOconnection, ADOTable and a Tmemo and a Tbutton...
procedure TForm1.Button1Click(Sender : TObject);
const SchemaID= '{947bb102-5d43-11d1-bdbf- 00c04fb926 75}';
var Schema: TSchemaInfo; Restrictions: OleVariant;
begin
Schema:= siProviderSpecific;
Restrictions:= 0; // not sure about this?
try with ADOConn do begin
Connected:= True;
OpenSchema(Schema, Restrictions, SchemaID, TADODataSet(tblADO)); //crashes here so must be wrong
end;
with tblADO do begin
First;
while not EOF do begin
AMemo.Lines.Add(Fields[0]. Name);
AMemo.Lines.Add(Fields[0]. Value);
Next;
end;
end;
except on e:exception do showmessage(e.message); end;
end;
by cloning cursors and using the BDE function "Check(DbiIsRecordLocked(T
I have searched about and came up with the code from Microsoft which uses OpenSchema with a SchemID which seems to not work (which I modified below).
I also checked some code which reads the LDB file, which I also have problems with as it is difficult to read this file, and anyway I dont feel its safe.
Anyone done this in Delphi already?
My test is like this so far (trying to load details into a memo), I guess I must not be understanding something :-))
I have 4 objects on a form: ADOconnection, ADOTable and a Tmemo and a Tbutton...
procedure TForm1.Button1Click(Sender
const SchemaID= '{947bb102-5d43-11d1-bdbf-
var Schema: TSchemaInfo; Restrictions: OleVariant;
begin
Schema:= siProviderSpecific;
Restrictions:= 0; // not sure about this?
try with ADOConn do begin
Connected:= True;
OpenSchema(Schema, Restrictions, SchemaID, TADODataSet(tblADO)); //crashes here so must be wrong
end;
with tblADO do begin
First;
while not EOF do begin
AMemo.Lines.Add(Fields[0].
AMemo.Lines.Add(Fields[0].
Next;
end;
end;
except on e:exception do showmessage(e.message); end;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
U should put a value to registry or an ini file... when application starts
if this is set when the application starts .. it means ur app was crashed
and u can delete the log in ur table
dont forget to add the workstation name to the log table ... cuz u must check log with username and workstation .. for multi user connections
if this is set when the application starts .. it means ur app was crashed
and u can delete the log in ur table
dont forget to add the workstation name to the log table ... cuz u must check log with username and workstation .. for multi user connections
ASKER
Good idea :-)
I had set a list of user names in a data file with a marker that he/she was logged in in the record, and
removed the marker when the app closed.
Problem was, if the app crashed the record was still tagged and then exceeded the "allowed user count" specified elsewhere.
Your solution will work I guess (not tried yet). Using this scenario, I assume that any file (ini, txt etc) local to each network
machine with a flag in it (e.g user name, y/n flag etc) will do, is that your idea?
I had set a list of user names in a data file with a marker that he/she was logged in in the record, and
removed the marker when the app closed.
Problem was, if the app crashed the record was still tagged and then exceeded the "allowed user count" specified elsewhere.
Your solution will work I guess (not tried yet). Using this scenario, I assume that any file (ini, txt etc) local to each network
machine with a flag in it (e.g user name, y/n flag etc) will do, is that your idea?
Hi AutoProSoftwareUK,
I used your code as a base for other question and we made it working,
if you are interested you can check:
https://www.experts-exchange.com/questions/24469369/MSAccess-User-List.html
Regards,
B.
I used your code as a base for other question and we made it working,
if you are interested you can check:
https://www.experts-exchange.com/questions/24469369/MSAccess-User-List.html
Regards,
B.
ASKER
What if the apllication crashes?