find computer/user using a database file

Hi,

In a multi user environment is it possible to identify the computer or user that is using a database file. IE I have a multi user system where at times there is a need to open the files exclusively (eg rebuild indexes), but when trying to open the files exclusively I can't because someone else is in the system - How can I identify who this is so that I can locate this user and ask them to exit the system.

Thanks
Clyde
clyde99Asked:
Who is Participating?
 
Stuart_JohnsonConnect With a Mentor Commented:
Hi Clyde,

No worries, mate.  Let's see if that article can help you or not.  I'll be home from work in about 4 hours, so I'll post something as soon as I locate it.

Stu
0
 
Stuart_JohnsonCommented:
I guess it depends on the type of database you're using.  MS SQL for instance only uses one file to hold all the tables, so the only way you'll be able to find out who's accessing them is to query the database system.

If you're accessing the database through an ODBC driver, then that may make it even more difficult that accessing it directly as the ODBC driver could contain the login details for one account and therefore be not user specific.

My guess would be, find out what database you are using, and then see if there's any APIs for it floating around.  If there are, you're chances of success are a lot greater.

Stu
0
 
clyde99Author Commented:
Thanks stu,

I am using the BDE with dbase tables - Any way you know of getting this information from the BDE?

Thanks
Clyde
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
SummaCommented:
Hi,

as far as I know this is only possible with
Paradox .db files. But I'm not sure...

Maybe this can help you.


a function for paradox-tables.
==============================================

uses BDE, ....;

....

procedure GetTableUsers(ATable: TTable; AStrings: TStrings);
var
  TmpCursor: hdbicur;
  LockInfo: LOCKDesc;
  Status: dbiResult;
begin
  Check(DbiOpenLockList(aTable.Handle, True, True, TmpCursor));
  Check(DbiSetToBegin(TmpCursor));
  Repeat
    Status := DbiGetNextRecord(TmpCursor, dbiNOLOCK, @LockInfo, Nil);
    AStrings.Add(LockInfo.szUserName);
  Until (Status <> DBIERR_NONE);
  Check(DbiCloseCursor(TmpCursor));
  Check(DbiCloseCursor(TmpCursor));
end;
0
 
Stuart_JohnsonCommented:
Hi Clyde,

I'm fairly sure you'll find Summa's suggestion will work with dBase tables.  I guess there is only one way to know for sure :)

Summa.  Can I ask where you obtained that code?  I quite often need a few low level DB routines and if it's from a library, I'd be interested to know where to get it.

Cheers folks,

Stu
0
 
clyde99Author Commented:
Hi Summa,

Thanks for the code snippet.

Unfortunately when I tried with a dbase file, the BDE came up with the exception error "Project1.exe raised exception class EDBEngineError with message 'Capability not supported'"

So it looks like this will not work with BDE and Dbase files.

Looks like I may have come to a dead end here unless anyone else has some other ideas?

Clyde
0
 
Stuart_JohnsonCommented:
Hi Clyde,

I had a thought last night.  Are the tables being served from an NT/2000/XP box?  If so, there is an administration tool which allows you to see who has what files open.  Perhaps there is a way you can find some info on what APIs that application uses and implement them in your program?  There was a big write up in The Delphi Magazine a few months ago about the Active Directory.  I believe there is ways of finding this sort of info out use the Active Directory.  I don't have the mag with me, but will check tonight and let you know.

Stu
0
 
clyde99Author Commented:
Hi Stu,

Yes, the Dbase files are on a Windows 2000 Server box(but I am not using active directory). However, I have used the admin tool that you refer to and If I could get access to that information via some API then that would solve my problem.

Thanks
Clyde
0
 
Stuart_JohnsonCommented:
Hi Clyde,

Does the admin tool show who's logged in, or is it just showing a generic (say SYSTEM) account??

I'll have a look for the info on Active Directories tonight and post you anything relevant.  You can actually go to their website and download previous issues cover disks, so if I give you the issue number, you'll be able to get the source code for it.

Stu
0
 
clyde99Author Commented:
Hi Stu,

The admin tool I refer to is "Computer Management" (from the control panel). When you drill down in this tool from "System Tools", then "Shared Folders", Through a combination of "Shares" and "Open Files" is all the information I need.

Clyde
0
 
SummaCommented:
for STU:
==========

>Summa.  Can I ask where you obtained that code?  I quite >often need a few low level DB routines and
>if it's from a library, I'd be interested to know where >to get it.

I found that snippet somewhere, but can't remember
the URL. Such BDE routines are very hard to find.
Look at the BDE-Help, there are some samples in it.


0
 
CleanupPingCommented:
clyde99:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.