Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about MSLDBUSR.DLL and user names

Status
Not open for further replies.

qwerty906

MIS
Jul 24, 2002
24
0
0
HK
hi all,

just a quick question that maybe you ppl know the answer to. I'm using the MSLDBUSR.DLL as a way to monitor my AC97 database. however i can only see the machine name, i can't see the actual usernames. i've set up user-level security and if i view the ldb file with notepad i can see the username, but for some reason the MSLDBUSR.DLL only returns the workstation name. am i doing something wrong here? thanks in advance.

jeff
 
Not really an answer to your question but there's a very handy product (free for personal use, I think) called the Jet Connections Monitor, available from - this let's you monitor who's connected to multiple databases at the same time, shows there machine name, database username, connect/disconnect times, etc.

I used to use MSLDBUSR.DLL, then tried parsing the LDB file, then (in A2000) wrote my own program using ADO to read Jet 4's user roster but none of these solutions is as easy to use as the Jet Connection Manager, which I now use all the time. [pc2]
 
thanks for the reply but it won't quite work for my setup. i want to incorporate the viewer into the administration module of the application, so apart from me parsing the ldb file i can't think of any other solutions. hmm i guess i'll play around it a bit more.
 
Here's another solution you can use then - the code isn't mine (I found it somewhere on the internet a year or so ago) but it works well. Essentially it parses the LDB file and adds the results (machine anme and DB username) to a list box.

To use, you need a form with a list box on it called LoggedOn. Then add the following function to the form's module.

Code:
Private Function WhosOn() As String

On Error GoTo Err_WhosOn

   Dim iLDBFile As Integer, iStart As Integer
   Dim iLOF As Integer, i As Integer
   Dim sPath As String, X As String
   Dim sLogStr As String, sLogins As String
   Dim sMach As String, sUser As String
   Dim rUser As UserRec    ' Defined in General
   Dim dbCurrent As Database

' Get Path of current database.  Should substitute this code
' for an attached table path in a multi-user environment.

   Set dbCurrent = DBEngine.Workspaces(0).Databases(0)
   sPath = dbCurrent.Name
   dbCurrent.Close

' Iterate thru dbCurrent.LDB file for login names.

   sPath = Left(sPath, InStr(1, sPath, ".")) + "LDB"

' Test for valid file, else Error

   X = Dir(sPath)
   iStart = 1
   iLDBFile = FreeFile

   Open sPath For Binary Access Read Shared As iLDBFile
   iLOF = LOF(iLDBFile)
   Do While Not EOF(iLDBFile)
      Get iLDBFile, , rUser
      With rUser
         i = 1
         sMach = ""
         While .bMach(i) <> 0
            sMach = sMach & Chr(.bMach(i))
            i = i + 1
         Wend
         i = 1
         sUser = &quot;&quot;
         While .bUser(i) <> 0
            sUser = sUser & Chr(.bUser(i))
            i = i + 1
         Wend
      End With
      sLogStr = sMach & &quot; -- &quot; & sUser
      If InStr(sLogins, sLogStr) = 0 Then
         sLogins = sLogins & sLogStr & &quot;;&quot;
      End If
      iStart = iStart + 64 'increment to next record offset
   Loop
   Close iLDBFile
   WhosOn = sLogins

Exit_WhosOn:
   Exit Function

Err_WhosOn:
   If Err = 68 Then
      MsgBox &quot;Couldn't populate the list&quot;, 48, &quot;No LDB File&quot;
   Else
      MsgBox Err.Number & &quot;: &quot; & Err.Description, vbExclamation
      Close iLDBFile
   End If
   Resume Exit_WhosOn

End Function

Then use the function by adding the following line to your form's OnOpen event.

Code:
    Me.LoggedOn.RowSource = WhosOn()
    Me.Caption = &quot;Users logged in @&quot; & Format(Now(), &quot;hh:nn:ss&quot;)

If you want to get even more flash you can use the form's timer event to get this list automatically refreshed at the interval of your choice. [pc2]
 
MP9,

I'm trying to use your code, seems very useful, when I try to open my form (LoggedOn) I get an error message..&quot;Method or data member not found&quot;...and Private Sub Form_Open is highlighted. Cant seem to figure this out, any suggestions?

Thanks,
Clark
Honda of America Manufact.,
 
MP9,

quick question sometimes after users log off the ldb is not updated and therefore is sometimes inaccurate, is there anyway around this. i used to do something similar to what you've done but i opened the file for random access instead of binary, does binary access solve this problem? thanks in advance

jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top