DisconnectUser

摘要

DisconnectUser 函数允许管理员断开当前连接到企业级地理数据库的用户连接。

说明

管理员可使用 DisconnectUser 函数断开用户与企业级地理数据库的连接。 此函数用于补充 ArcGIS Pro 中的地理数据库管理对话框。

  • DisconnectUser 函数必须使用连接到数据库的管理连接。
  • 如果非管理员用户尝试运行此函数,则函数失败。
  • 选择除用于运行函数或数据库的管理员连接之外的所有用户,断开其连接。

语法

DisconnectUser (sde_workspace, {users})
参数说明数据类型
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.
注:

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

Integer

代码示例

DisconnectUser 示例 1

以下示例说明如何断开所有用户与地理数据库的连接。

import arcpy

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

以下示例演示了运行该命令断开单个用户连接的方法。 在本例中,管理员按照 ListUsers 函数返回的用户名列表提取要断开连接的用户 SDE ID。

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 示例 3

以下示例演示了运行 DisconnectUser 函数断开多个用户连接的方法。

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)

相关主题