Select to view content in your preferred language

Automated method to check if enterprise geodatabase is accepting connections?

1893
5
12-13-2021 09:19 AM
Brownschuh
Frequent Contributor

Our organization has a database maintenance script that runs nightly. Without going into too much detail of the script tasks, the first task is to stop any connections to the GDB and the last step is to open connections back to the GDB. While it is rare, once a blue moon the script will stop during a run and not allow for database connections. We usually find this out when the end users are prompted with an error message the next morning and we have to manually check the box to allow for connections.  I should note we do have safeguards in place if the script runs into any geoprocessing errors; the script will send admin users an email message of the error that was encountered and reestablish database connections as a final step. However, there are the strange instances where the script will stop completely with no errors, thus not taking that final step to accept connections.

My questions is: is there a way using python to check if an enterprise geodatabase is accepting connections?

Ideally I would like to write a simple script that performs the following tasks:
1. Check if GDB is accepting connections
2. If yes, end script
3. If no, send an alert message to admins and accept connections

0 Kudos
5 Replies
George_Thompson
Esri Notable Contributor

Take a look at this: https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/acceptconnections.htm

Looks like it is what you are looking for.

--- George T.
0 Kudos
Brownschuh
Frequent Contributor

Thank you for the reply.  We already use the AcceptConnections function to block or accept connections in our database maintenance scripts.  What I'm looking for is a way to check if connections are blocked/open.

0 Kudos
George_Thompson
Esri Notable Contributor

Ah, you are correct. Sorry I did not fully gather that. I am not sure of a way, but have seen a thread mention it: https://gis.stackexchange.com/questions/14677/can-arcpy-test-for-availability-of-sde-connection-befo...

You may also want to add something like a describe (https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/featureclass-properties.htm)  on a specific feature class in the DB to see if it works.

 

--- George T.
0 Kudos
VishApte
Esri Contributor

I cannot see arcpy function to test if geodatabase is accepting connections. Quick SQL trace tells me that ArcGIS checks it using following SQL statement

SELECT num_prop_value FROM DBNAME.sde.SDE_server_config WHERE prop_name = 'STATUS'

And if the value is 2, it is NOT accepting connections. Value 1 means it is.

Following python code may help.

import arcpy
import os
def is_accepting_connections(sde_conn_nonadmin):
if (os.path.exists(sde_conn_nonadmin) == False):
raise ValueError("Invalid SDE connection file '{}'".format(sde_conn_nonadmin))
try:
arcpy.env.workspace = sde_conn_nonadmin
desc = arcpy.Describe(sde_conn_nonadmin)
if (hasattr(desc, 'workspaceType')):
return True
else:
return False
except:
raise

 

0 Kudos
Brownschuh
Frequent Contributor

Bummer, I was hoping there would be an arcpy function to test if a GDB is accepting connections.  Maybe ESRI can include that functionality in future releases?

0 Kudos