I am trying to automate my administrative processes with Python for my enterprise geodatebase. I basically took the script at the end found here: Use Python scripting to batch reconcile and post versions—ArcGIS Help | ArcGIS Desktop and trimmed out the parts I do not need. I cannot for the life of me figure out why it bombs when run via a scheduled task.
Using 10.6.1, sde is the admin level, gis user is the owner of the data.
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token">#, time, smtplib</SPAN>
<SPAN class="comment token"># Set the workspace</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'C:\Users\GISAdmin\AppData\Roaming\ESRI\Desktop10.6\ArcCatalog\SDE to GIS2.sde'</SPAN>
<SPAN class="comment token"># sde is the user that can disconnect users</SPAN>
<SPAN class="comment token"># gis is the owner of of all the data</SPAN>
<SPAN class="comment token"># Set a variable for the workspace</SPAN>
adminConn <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace
<SPAN class="comment token"># Block new connections to the database.</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"The database is no longer accepting connections"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AcceptConnections<SPAN class="punctuation token">(</SPAN>adminConn<SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Credit Card Declined"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Wait 15 minutes</SPAN>
<SPAN class="comment token">#time.sleep(900)</SPAN>
<SPAN class="comment token"># Disconnect all users from the database.</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Disconnecting all users"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>DisconnectUser<SPAN class="punctuation token">(</SPAN>adminConn<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ALL"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Disconnected Users"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Get a list of versions to pass into the ReconcileVersions tool.</SPAN>
<SPAN class="comment token"># Only reconcile versions that are children of Default</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Compiling a list of versions to reconcile"</SPAN><SPAN class="punctuation token">)</SPAN>
verList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListVersions<SPAN class="punctuation token">(</SPAN>adminConn<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#versionList = [ver.name for ver in verList if ver.parentVersionName == 'sde.DEFAULT']</SPAN>
<SPAN class="keyword token">print</SPAN> verList
<SPAN class="comment token"># Execute the ReconcileVersions tool.</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Reconciling all versions"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>ReconcileVersions_management<SPAN class="punctuation token">(</SPAN>adminConn<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"ALL_VERSIONS"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"sde.DEFAULT"</SPAN><SPAN class="punctuation token">,</SPAN> u<SPAN class="string token">'WEBSERVICES.WebEdits'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"LOCK_ACQUIRED"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"NO_ABORT"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"BY_OBJECT"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"FAVOR_TARGET_VERSION"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"POST"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"KEEP_VERSION"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"c:/ArcGISscripts/ReconcileLogs/Temp/reconcilelog.txt"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Reconcile Complete"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Run the compress tool.</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Running compress"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Compress_management<SPAN class="punctuation token">(</SPAN>adminConn<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Compression Complete"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Allow the database to begin accepting connections again</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Allow users to connect to the database again"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AcceptConnections<SPAN class="punctuation token">(</SPAN>adminConn<SPAN class="punctuation token">,</SPAN> <SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Communications Back On Line Captain"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Update statistics and indexes for the system tables</SPAN>
<SPAN class="comment token"># Note: to use the "SYSTEM" option the user must be an geodatabase or database administrator.</SPAN>
<SPAN class="comment token"># Rebuild indexes on the system tables</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Rebuilding indexes on the system tables"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>RebuildIndexes_management<SPAN class="punctuation token">(</SPAN>adminConn<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SYSTEM"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Rebuilt Indexes"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Update statistics on the system tables</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Updating statistics on the system tables"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>AnalyzeDatasets_management<SPAN class="punctuation token">(</SPAN>adminConn<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"SYSTEM"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Analyzed Data sets"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"YAY!!! We Finished For Once."</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>