DisconnectUser (arcpy)
摘要
允许管理员断开当前连接到企业级地理数据库的用户连接。
讨论
管理员可使用 DisconnectUser 函数断开用户与企业级地理数据库的连接。该函数可用于补充 ArcGIS for Desktop 中的“已连接用户”对话框。
- DisconnectUser 功能必须使用数据库的管理连接。
- 如果试图通过非管理员帐户运行该功能,将无法执行操作。
- 选择所有用户,将断开所有用户的连接,用于执行该操作及据库的管理员除外。
语法
DisconnectUser (sde_workspace, {users})
参数 | 说明 | 数据类型 |
sde_workspace |
The Enterprise geodatabase containing the users to be disconnected. The connection properties specified in the Enterprise Geodatabase must have administrative rights that allow the user to disconnect other connections. | String |
users [users,...] |
Specifies which users will be disconnected from the geodatabase.
注: DisconnectUser will not disconnect the user who is executing the function. | Integer |
代码实例
DisconnectUser 示例 1
以下示例说明了从地理数据库断开所有用户连接的方法。
import arcpy
arcpy.DisconnectUser("Database Connections/admin@sde.sde", "ALL")
DisconnectUser 示例 2
以下示例演示了断开单一用户连接的命令行。在本例中,管理员按照 ListUsers 函数返回的用户名列表提取要断开连接的用户 SDE ID。
import arcpy
admin_workspace = "Database Connections/tenone@sde.sde"
arcpy.env.workspace = admin_workspace
user_name = "GDB"
# Look through the users in the connected user list and get the SDE ID.
# Use the SDE ID to disconnect the user that matches the username variable
users = arcpy.ListUsers() # The environment is set, no workspace is needed.
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 = "Database Connections/tenone@sde.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 userNamesList created earlier:
for user in connected_users:
if user.Name in user_names:
print('Disconnecting {0}'.format(user.Name))
arcpy.DisconnectUser(admin_workspace, user.ID)
相关主题
9/15/2013