Skip to main content

ListUsers

Summary

The ListUsers function returns a list of named tuples containing information for users who are connected to an enterprise geodatabase.

Discussion

The ListUsers function is used by an administrative user to identify users who are currently connected to an enterprise geodatabase.

  • The ListUsers function must use an administrative connection to the database.

  • This function will fail if it's attempted by a nonadministrative user.

Syntax

ListUsers(sde_workspace)

Parameter Explanation Data Type

sde_workspace

An enterprise geodatabase (sde connection file).

The connection properties specified in the enterprise geodatabase must have administrative rights that allow the user to disconnect other connections.

String

Return value

Data Type Explanation

tuple

The ListUsers function returns a list of named tuples. The named tuples returned each have the following items:

  • ClientName—The name of the client machine where the connection is being made.

  • ConnectionTime—The datetime when the user made the initial connection to the geodatabase.

  • ID—The enterprise database connection identifier. This is the value that can be used in the DisconnectUser function to identify the user to disconnect.

  • IsDirectConnection—True if the connection is a direct connection (two-tier). False if the connection is an application server connection (three-tier).

  • Name—The name of the user who is connected to the database.

Code sample

ListUsers example 1
import arcpy

arcpy.ListUsers("C:\\MyProject\\admin.sde")
ListUsers example 2

The following example demonstrates how to print a list of connected users along with their connection time.

import arcpy

users = arcpy.ListUsers("C:\\MyProject\\admin.sde")
for user in users:
    print("Username: {0}, Connected at: {1}".format(
        user.Name, user.ConnectionTime))
ListUsers example 3

The following example demonstrates how to generate a new list of only SDE IDs from the list returned by the ListUsers function.

import arcpy

# Set the admistrative workspace connection
arcpy.env.workspace = "C:\\MyProject\\admin.sde"
admin = arcpy.env.workspace

# Create a list of users
users = arcpy.ListUsers(admin)

# Create a list of SDE ID's.
# Use a list comprehension to get the ID values in a new list.
id_users = [user.ID for user in users]
print(id_users)