How do I reestablish a database connection after compressing in a script?

227
1
05-30-2019 08:26 AM
HenryBernberg
New Contributor

I have a script that needs to run a database compression in the middle so that I can run a SQL update statement. I allow new connections again after the compression, but the script fails because it can't see the database any longer. Is there any way to force the script to reconnect to the database after?

Here's a sample of the code. The first Exists shows the feature class is there, but the second one can't see it.

if arcpy.Exists(ACCOUNTS):
   print "ACCOUNTS exists"
else: print "ACCOUNTS doesn't exist"

arcpy.AcceptConnections(SDE_Connection, False)
arcpy.DisconnectUser(SDE_Connection, "ALL")
arcpy.Compress_management(SDE_Connection)
arcpy.AcceptConnections(SDE_Connection, True)

if arcpy.Exists(ACCOUNTS):

   print "ACCOUNTS exists"
else: print "ACCOUNTS doesn't exist"

0 Kudos
1 Reply
MichaelRomankiewicz
New Contributor II

GREAT question. I am having the exact same issue. Hoping ESRI can provide some insight.

0 Kudos