DisconnectUser

Zusammenfassung

The DisconnectUser function allows an administrator to disconnect users who are currently connected to an enterprise geodatabase.

Diskussion

The DisconnectUser function is used by an administrative user to disconnect users from an enterprise geodatabase. This function is used to complement the Geodatabase Administration dialog box in ArcGIS Pro.

  • The DisconnectUser function must use an administrative connection to the database.
  • If a nonadministrative user attempts to run this function, the function will fail.
  • Selecting all users will disconnect all users other than the administrator connection used to run the function or database.

Syntax

DisconnectUser (sde_workspace, {users})
ParameterErläuterungDatentyp
sde_workspace

The enterprise geodatabase the users will be disconnected from.

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

String
users
[users,...]

Specifies the users who will be disconnected from the geodatabase.

  • sde_idUsers will be disconnected based on the ID value returned from the ListUsers function. This can be passed to the function as an individual SDE ID value or a list containing multiple SDE ID values.
  • ALLAll connected users will be disconnected.
Hinweis:

This function will not disconnect the user who is running the function.

Integer

Codebeispiel

DisconnectUser example 1

The following example demonstrates how to disconnect all users from a geodatabase.

import arcpy

arcpy.DisconnectUser("D:\\MyProject\\admin.sde", "ALL")
DisconnectUser example 2

The following example demonstrates how to run the command to disconnect a single user. In this example, the SDE ID is extracted based on the name of the user that the administrator wants to disconnect from the list returned from the ListUsers function.

import arcpy

admin_workspace = "D:\\MyProject\\admin.sde"
arcpy.env.workspace = admin_workspace
user_name = "GDB"

# Look through the users in the connected user list and get the connection ID.
# Use the connection ID to disconnect the user that matches the username variable
users = arcpy.ListUsers(admin_workspace)
for item in users:
    if item.Name == user_name:
        arcpy.DisconnectUser(admin_workspace, item.ID)
DisconnectUser example 3

The following example demonstrates how to run the DisconnectUser function to disconnect multiple users.

import arcpy

# Set the admistrative workspace connection
admin_workspace = "D:\\MyProject\\admin.sde"

# Create a list of users to disconnect.
user_names = ["TRAVIS", "DEBBIE", "PHIL"]

# Get a list of connected users
connected_users = arcpy.ListUsers(admin_workspace)

# Loop through the list of connected users and execute DisconnectUser
# if the user name is in the user_names list
for user in connected_users:
    if user.Name in user_names:
        print('Disconnecting {0}'.format(user.Name))
        arcpy.DisconnectUser(admin_workspace, user.ID)

Verwandte Themen