Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to determine who is logged on to a database by using Microsoft Jet UserRoster in Access 2000


Advanced: Requires expert coding, interoperability, and multiuser skills.

IN THIS TASK

↑ Back to the top


Summary

By using Microsoft Visual Basic for Applications in Microsoft Access 2000, you can output a list of users who are logged into a database. The code example in this article show you how to do this.


Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The user list feature provides a way of determining who is currently connected to a Microsoft Jet database. The list can be obtained via the ADO programming interface and returns the following information for each user:
  • Name of the computer that the user is using.
  • Security name, that is, the user ID.
  • Whether or not the user is currently connected to the database. (A user's ID remains in the lock database until the last user disconnects or until the slot is reclaimed for a new user connection.)
  • Whether or not the user connection was terminated normally.
  • The user list capability can be used in conjunction with the connection control capability to determine which users are still connected, so that they can be asked to disconnect.
The user list capability is also useful in isolating problems with database corruption that is associated with the activities of a specific user.

Code Example

To demonstrate the code example, follow these steps:

NOTE: The sample code in this article uses Microsoft ActiveX Data Objects. For this code to run properly, you must reference the Microsoft ActiveX Data Objects 2.x Library (where 2.x is 2.1 or later.) To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft ActiveX Data Objects 2.x Library check box is selected.

  1. Copy the Northwind sample database the C:\ folder.
  2. In Microsoft Access, open C:\Northwind.
  3. In the Database Window, click Modules under Objects, and then click New.
  4. Save the module as ShowUsers.
  5. Type the following code in the new ShowUsers module:
    Sub ShowUserRosterMultipleUsers()
    Dim cn As New ADODB.Connection
    Dim cn2 As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim i, j As Long

    cn.Provider = "Microsoft.Jet.OLEDB.4.0"
    cn.Open "Data Source=c:\Northwind.mdb"

    cn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
    & "Data Source=c:\Northwind.mdb"

    ' The user roster is exposed as a provider-specific schema rowset
    ' in the Jet 4 OLE DB provider. You have to use a GUID to
    ' reference the schema, as provider-specific schemas are not
    ' listed in ADO's type library for schema rowsets

    Set rs = cn.OpenSchema(adSchemaProviderSpecific, _
    , "{947bb102-5d43-11d1-bdbf-00c04fb92675}")

    'Output the list of all users in the current database.

    Debug.Print rs.Fields(0).Name, "", rs.Fields(1).Name, _
    "", rs.Fields(2).Name, rs.Fields(3).Name

    While Not rs.EOF
    Debug.Print rs.Fields(0), rs.Fields(1), _
    rs.Fields(2), rs.Fields(3)
    rs.MoveNext
    Wend

    End Sub
  6. Close the Northwind database and when prompted, save changes to ShutDownDB (This must be done to release an exclusive lock on the database due to the code you have just added).
  7. Re-open C:\Northwind.
  8. Press CTRL+G to open the Immediate Window in the Visual Basic Editor.
  9. Type the following in the Immediate window and press ENTER:
    ShowUserRosterMultipleUsers
    Note that in the Immediate window returns a list of users in the database.

↑ Back to the top


Keywords: kbprogramming, kbvba, kbado, kbinfo, kbsweptsoltax, kbhowtomaster, kb, kbarchive

↑ Back to the top

Article Info
Article ID : 198755
Revision : 1
Created on : 1/7/2017
Published on : 6/23/2005
Exists online : False
Views : 447