Python Script to Disconnect all users from a database

5186
5
05-09-2014 10:21 AM
BenDrury
Occasional Contributor
I am not very Python savvy...  trying to develop a script to disconnect all users from a 10.2.2 SDE database.  Can anyone tell me what I'm doing wrong?


import arcinfo

import arcpy


# Variables:
sde_TestServer = "\\\\computer\\c$\\Users\\user\\AppData\\Roaming\\ESRI\\Desktop10.2\\ArcCatalog\\sde@TestServer.sde"

#Disconnect Users
arcpy.DisconnectUser ("sde_TestServer", "ALL")



THANKS!
Tags (2)
0 Kudos
5 Replies
JoshuaChisholm
Regular Contributor
You are python savvy Katherine! You're only missing one thing: take the quotes away from sde_TestServer. Like this:
import arcinfo
import arcpy

# Variables:
sde_TestServer = "\\\\computer\\c$\\Users\\user\\AppData\\Roaming\\ESRI\\Desktop10.2\\ArcCatalog\\sde@TestServer.sde"

#Disconnect Users
arcpy.DisconnectUser (sde_TestServer, "ALL")


The reason: if python sees "sde_TestServer" it reads it as the string "sde_TestServer". If python sees sde_TestServer it looks for a variable that was previously set using that name.
0 Kudos
AimeiChen
Occasional Contributor

Hi, Josh

Id like to have this handy tool as well. But I was running into an error, says Connection information provided was for a non-administrative user. But the user "msdgc" can disconnect user from ArcCatalog.  would you please help, thanks!

Amy

import arcinfo
import arcpy

# Variables: 
sde_Server = "c:\\Users\\user\\AppData\\Roaming\\ESRI\\Desktop10.1\\ArcCatalog\\msdgc@msdtest.sde" 

arcpy.DisconnectUser(sde_Server, "ALL")

Traceback (most recent call last):

  File "C:\Program Files (x86)\SystemScheduler\disconnectuser.py", line 8, in <module>

    arcpy.DisconnectUser(sde_Server, "ALL")

  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\__init__.py", line 1040, in DisconnectUser

    return gp.disconnectUser(sde_workspace, users)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda>

    return lambda *args: val(*gp_fixargs(args, True))

RuntimeError: Connection information provided was for a non-administrative user

0 Kudos
BenDrury
Occasional Contributor

Are you using a SDE user Connection to establish this? It needs to be either the SDE user or possibly the SA user for it to work properly, preferably the SDE user

0 Kudos
AimeiChen
Occasional Contributor

I switched to SDE user but still got same error message. Thanks!

0 Kudos
AsrujitSengupta
Regular Contributor III

Does the sde user have "processadmin" fixed server role?

0 Kudos