import arcpy connectionFile = r"<path\to>\connection.sde" #block new connections to the database. arcpy.AcceptConnections(connectionFile, False) #disconnect all users from the database. arcpy.DisconnectUser(connectionFile, "ALL") # do work here #allow new connections to the database. arcpy.AcceptConnections(connectionFile, True)