...almost had it --- add to your search string 'users', i.e., 'disconnect users' and should get this which I think is what you are looking for:
DisconnectUser (arcpy)
Desktop » Geoprocessing » ArcPy » ArcPy functions
http://resources.arcgis.com/en/help/main/10.1/index.html#//018v00000061000000
So in the very 1st example, there is this:
arcpy.DisconnectUser("Database Connections/admin@sde.sde", "ALL")
I don't have ArcGIS 10.1 installed yet so cannot test it...but if it works, this is much better than the 'disconnection procedure' I have used before.
...you may want to test for who/what is connected first, with:
ListUsers (arcpy)
Desktop » Geoprocessing » ArcPy » ArcPy functionshttp://resources.arcgis.com/en/help/main/10.1/index.html#//018v00000030000000
ahh, but there is a catch, probably a design feature 'failsafe' not to accidentally disconnect the admin user - from the webhelp:
"Note: DisconnectUser will not disconnect the user who is executing the function."
>>> # the pathname as you have stated it: >>> pathname = "r'Database Connections\Sa_D1.sde'" >>> # this is incorrect, directly converting all inside the double-quotes to string: >>> print pathname r'Database Connections\Sa_D1.sde' >>> # removing the double-quotes: >>> pathname = r'Database Connections\Sa_D1.sde' >>> # this is correct, with 'r' serving in Python to use raw string: >>> print pathname Database Connections\Sa_D1.sde >>> # quick example of raw versus non-raw interpretation: >>> # this is without the preceding 'r': >>> nonRawExample = '\tAtest' >>> # this string is actually interpreted to include a tab: >>> print nonRawExample Atest >>> # this string includes the preceding 'r' for the raw representation: >>> useRawExample = r'\tAtest' >>> # as desired, the string is interpreted as is, or 'raw', to include the backslash character: >>> print useRawExample \tAtest
# the ReconcileVersions pathname strings inputDB = r'\\YourServerUNC\folderMaybeThisContainsType\SDEfiles\admins.sde' logFile = r'C:\temp\reconcilelog.txt' # other ReconcileVersions defined params all = 'ALL_VERSIONS' target = 'sde.DEFAULT' versionList = arcpy.ListVersions(inputDB) lock = 'LOCK_ACQUIRED' abort = 'NO_ABORT' conflict = 'BY_OBJECT' resolve = 'FAVOR_TARGET_VERSION' post = 'POST' deleteVer = 'DELETE_VERSION' # Execute the ReconcileVersions tool. arcpy.ReconcileVersions_management(inputDB, all, target, versionList, lock, abort, conflict, resolve, post, deleteVer, logFile)
Your mistake is with the pathname string - you are mixing conventions. I prefer to stick with passing 'raw' strings so that I do not generally have to concern myself further with backslashes being interpreted by python as an escape sequence (the preceding 'r' means interpret as 'raw' string) -- see the below where I am testing the strings via IDLE:>>> # the pathname as you have stated it: >>> pathname = "r'Database Connections\Sa_D1.sde'" >>> # this is incorrect, directly converting all inside the double-quotes to string: >>> print pathname r'Database Connections\Sa_D1.sde' >>> # removing the double-quotes: >>> pathname = r'Database Connections\Sa_D1.sde' >>> # this is correct, with 'r' serving in Python to use raw string: >>> print pathname Database Connections\Sa_D1.sde >>> # quick example of raw versus non-raw interpretation: >>> # this is without the preceding 'r': >>> nonRawExample = '\tAtest' >>> # this string is actually interpreted to include a tab: >>> print nonRawExample Atest >>> # this string includes the preceding 'r' for the raw representation: >>> useRawExample = r'\tAtest' >>> # as desired, the string is interpreted as is, or 'raw', to include the backslash character: >>> print useRawExample \tAtest
Additionally, this is a matter of preference, but I prefer whenever possible to pass variables, not strings, to my tool, as in this example, particularly when there are a number of params to feed in - such as the 11 params for ReconcileVersions:# the ReconcileVersions pathname strings inputDB = r'\\YourServerUNC\folderMaybeThisContainsType\SDEfiles\admins.sde' logFile = r'C:\temp\reconcilelog.txt' # other ReconcileVersions defined params all = 'ALL_VERSIONS' target = 'sde.DEFAULT' versionList = arcpy.ListVersions(inputDB) lock = 'LOCK_ACQUIRED' abort = 'NO_ABORT' conflict = 'BY_OBJECT' resolve = 'FAVOR_TARGET_VERSION' post = 'POST' deleteVer = 'DELETE_VERSION' # Execute the ReconcileVersions tool. arcpy.ReconcileVersions_management(inputDB, all, target, versionList, lock, abort, conflict, resolve, post, deleteVer, logFile)
Hope that helps - I think it makes the code a little more readable and accessible for troubleshooting.
Enjoy,
Wayne
You were before having problems establishing your admin sde connection via Python - I don't know if it was clear but (provided the sde connection files contain valid parameters at the Database Connections shortcut set up in ArcGIS [I think the default location is in the app directory]) you can use the line of code below, if this is the valid admin connection you desire setting up for the reconcile/post process:
arcpy.env.workspace = r'Database Connections\Sa_D1.sde'
I mentioned using UNC pathname conventions -- what I mean by that is I prefer not to use the 'Database Connections' shortcut, because for one what if the default setting for the shortcut path is overridden?...then where is your script supposed to go look for it? If such things change, then you have to remember to also move the appropriate sde connection files to the new location.
Therefore, as a result of this reasoning (and this particularly applies to running scripts from the server and any specialized scripts you want to provide a 'more private' or secure location to use, accessing the file-contained connection parameters), it is convenient to store scripts and any associated sde files, etc. needed to run it on the server --- for example:
arcpy.env.workspace = r'\\yourServerName\aMoreSecureLocation\aCopyOf\Sa_D1.sde'
You can even copy your sde file there if that is the convenience you want - and in that way you have secured a file for particular use by your server scripts...it is true if you do this you will have to maintain them separately, but how often do you have to change admin connection files? It certainly doesn't make sense to store the files on your desktop for the server to 'reach across the network' for the necessary params in order to do its assigned admin task on the server!
Just thought I'd pass that along. Hope it is going well -- the 'batch' workflow (Using Python scripting to batch reconcile and post versions) listed at the 10.1 webhelp is extremely interesting....so if you will post back here to confirm you got it going, that would be great.
Thanks,
Wayne
Caveman simple: Stop and start the service. It's never failed me...