Whos connected to MS Access?

Posted on 2000-02-28
Last Modified: 2011-04-14
Hi experts.

I am using MS Access as a network database.
is MS Access resides on a server and clients would point to the server's mdb file to use as their database file.

If at any time I would like to see whos connected to the database, how would I do that? (Programmatically ..)

Thanks experts :)

Question by:kaiser18au

Accepted Solution

jelliott720 earned 100 total points
ID: 2568377
Microsoft has a set of utilities for downloading that can help. These utilities are contained in the file jetutils.exe. The Msldbusr.exe example contained therein is what your looking for... just follow the link...

Hope this helps...


Expert Comment

ID: 2568477
You should perhaps look at setting up Access security.

This would enable you to log access to the Access database you require.
You could then read the Access log programmatically to determine which users are connected.

Let me know if you need some guidelines in setting up Access security.

LVL 70

Expert Comment

by:Éric Moreau
ID: 2568830

Author Comment

ID: 2575253

I wonderering if anyone could help in with this.

I found this article, which allows me to show up the users connected to the DB, but it is implemented as a  function in the MS Access module.

I need to call this from VB to show up connections in my app. Is there any possibility to return the recordset from this function to my app.



PSS ID Number: Q198756
Article last modified on 05-26-1999

The information in this article applies to:
 - Microsoft Access 2000
Advanced: Requires expert coding, interoperability, and multiuser skills.
Using Microsoft Visual Basic for Applications in Microsoft Access, you can
prevent users from logging on to a Jet database. If users are already in the
database, they will remain logged on; however, no other users will be able to
open the database. This is called a passive shutdown.
The code example in this article demonstrates how to perform a passive shutdown
and as well how to output a list of users who are already logged on to the
The Connection Control
The connection control (also known as passive shutdown) feature prevents users
from connecting to a database. This capability is useful for a database
administrator who needs to acquire exclusive access to a database to perform
maintenance, for example, compacting the database, or who needs to make updates
to the database schema or applications.
When connection control is invoked, users currently connected to a database will
remain unaffected until the disconnect. At that point, they are unable to
reconnect until connection control is revoked.
The following scenarios provide additional insight into how this capability
 - Five users are in the database. User five initiates passive shutdown. User
   six tries to connect to the database, but is denied access and an error
   message is returned stating that user five is preventing the database from
   being opened.
 - Five users are in the database. User five initiates passive shutdown. User
   one closes the database and tries to reconnect to the database, but is denied
   access and an error message is returned stating that user five is preventing
   the database from being opened.
 - Five users are in the database. User five initiates passive shutdown. User
   five closes the database. User six tries to open the database and is
   successful. This is because passive shutdown only persists while the user
   that called it remains connected to the database.
 - Five users are in the database. User five initiates passive shutdown. Users 1
   through four exit the database. User five calls the user list functionality
   and determines that no other users are in the database. User five closes the
   database and immediately compacts the database.
The User List
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 being used.
 - 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
Microsoft provides programming examples for illustration only, without warranty
either expressed or implied, including, but not limited to, the implied
warranties of merchantability and/or fitness for a particular purpose. This
article assumes that you are familiar with the programming language being
demonstrated and the tools used to create and debug procedures. Microsoft
support professionals 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 needs. If you have
limited programming experience, you may want to contact a Microsoft Certified
Solution Provider or the Microsoft fee-based consulting line at (800) 936-5200.
For more information about Microsoft Certified Solution Providers, please see
the following page on the World Wide Web:
For more information about the support options available from Microsoft, please
see the following page on the World Wide Web:
To demonstrate the code example, follow these steps:
1. Copy the Northwind example database to the C:\ directory.
2. In Microsoft Access, open C:\Northwind.
3. Create a new module called ShutDownDB.
4. On the Tools menu, click References.
5. In the References dialog box, click to select the following reference:
   Microsoft ActiveX Data Objects 2.1 Library
6. With the above Reference selected, use the Priority button to move the
   reference above the reference to Microsoft DAO 3.6 Object Library.
7. Type the following code in the new module:
   Sub ShowUserRosterAndPassiveShutdown()
      Dim cn As New Connection
       Dim cn2 As New Connection
       Dim cn3 As New Connection
       Dim rs As New Recordset
      Dim i, j As Long
      On Error GoTo ErrHandler
      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"
      ' Restrict other users from opening the database
      cn.Properties("Jet OLEDB:Connection Control") = 1
      ' Attempt to open another connection to the database
      cn3.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, , _
      ' 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)
      ' Close one of the remaining connections
      ' Reopen the user roster to verify that no other users are in the
      ' database Output the list of all users in the current database.
      Set rs = cn.OpenSchema(adSchemaProviderSpecific, , _
      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)
      Exit Sub
      For j = 0 To cn.Errors.Count - 1
         Debug.Print "Conn Err Num : "; cn.Errors(j).Number
         Debug.Print "Conn Err Desc: "; cn.Errors(j).Description
      Next j
      For j = 0 To cn2.Errors.Count - 1
         Debug.Print "Conn Err Num : "; cn2.Errors(j).Number
         Debug.Print "Conn Err Desc: "; cn2.Errors(j).Description
      Next j
      For j = 0 To cn3.Errors.Count - 1
         Debug.Print "Conn Err Num : "; cn3.Errors(j).Number
         Debug.Print "Conn Err Desc: "; cn3.Errors(j).Description
      Next j
      Resume Next
   End Sub
8. 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.)
9. Re-open C:\Northwind.mdb.
10. Press CTRL+G to bring up the Immediate Window in the Visual Basic Editor.
11. Type the following in the Immediate window and press ENTER:
Note the list of database users displayed in the Immediate window.
Additional query words: inf
Keywords          : kbdta AccCon KbVBA
Version           : WINDOWS:2000
Platform          : WINDOWS
Issue type        : kbhowto
Copyright Microsoft Corporation 1999.


Author Comment

ID: 2589297

Many thank yous for the link. That utility had the DLL that I need to do what I wanted to do.

Thanks again.



Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ms access #TYPE! error on report when no data 4 75
Cannot enter table caption text in Word protected document 6 123
Copy a row 12 61
IF ELSE Statement in Excel Macro VBA 16 62
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now