Skip to main content

Identify and remove connections from a geodatabase in SAP HANA using Python

Available with the Standard or Advanced license.

As the geodatabase administrator, you can use ArcPy functions to find and remove other users' connections from the geodatabase.

Note:

See manage connections to an enterprise geodatabase for steps to identify and remove connections using the Geodatabase Administration dialog box and to prevent new connections.

You can run ArcPy functions to create a geodatabase connection file for the sde user, use that connection file to connect to the geodatabase and get a list of all current geodatabase connections, and remove a connection from the geodatabase if necessary.

  1. Create a database connection file by running the CreateDatabaseConnection_management function in a Python window. Save the username and password with the file.

    You must connect to the geodatabase as the sde user. The sde user must have SESSION ADMIN permission in the database to disconnect users from a geodatabase in SAP HANA.

    In this example, a connection file (saphana.sde) is created in the user's dbconnections directory. The connection file creates a connection to a database named spsap, logged in as the sde user.

    import arcpy
    arcpy.management.CreateDatabaseConnection (
      "/usr/dbconnections",
      "saphana.sde",
      "SAPHANA",
      "spsap",
      "DATABASE_AUTH",
      "sde",
      "thesdepwd",
      "SAVE_USERNAME"
    )
    
  2. Run the ListUsers function to get a list of all current connections to the geodatabase.

    Provide the connection file you created in the previous step.

    ##No need to import arcpy if you are running functions in the same Python window.
    import arcpy
    
    arcpy.ListUsers("/usr/dbconnections/saphana.sde")
    

    A list of user connections is returned.

    [user(ClientName=u'PC4', ConnectionTime=datetime.datetime(2018, 10, 18, 8, 30, 19),
     ID=18, IsDirecConnection=True, Name=u'PUBLISHER1')]
    [user(ClientName=u'PC25', ConnectionTime=datetime.datetime(2018, 10, 21, 14, 10, 43),
     ID=33, IsDirecConnection=True, Name=u'EDITOR2')]
    [user(ClientName=u'PC11', ConnectionTime=datetime.datetime(2018, 10, 22, 9, 18, 26),
     ID=39, IsDirecConnection=True, Name=u'READER5')]
    [user(ClientName=u'PCA2', ConnectionTime=datetime.datetime(2018, 10, 22, 11, 21, 2),
     ID=41, IsDirecConnection=True, Name=u'SDE')]
    
  3. Contact individuals and ask them to close their sessions. If you are unable to contact them and still need to disconnect them from the geodatabase, proceed with the next step.

  4. Use the information obtained from the ListUsers function to identify the connection to remove using the DisconnectUser function.

    Specify the ID of the connection to remove. Here, the connection with ID 33 is removed:

    ##No need to import arcpy if you are running functions in the same Python window.
    import arcpy
    
    arcpy.DisconnectUser("/usr/dbconnections/saphana.sde",33)
    

    The connection is immediately dropped from the geodatabase.