Clear Workspace Cache (Data Management)
Summary
Clears any ArcSDE workspaces from the ArcSDE workspace cache.
Usage
-
This tool only works with ArcSDE workspaces.
-
This tool can be used to help disconnect idle ArcSDE connections in a long-running application.
-
If you run the tool without specifying an Input data element, all ArcSDE workspaces in the ArcSDE workspace cache will be cleared. Specify the specific .sde file associated with the workspace you want to clear in order to clear a specific ArcSDE workspace.
- To clear the workspace cache correctly in ArcCatalog: After using this tool in ArcCatalog you will have to navigate to a different folder in the Table of Contents and refresh before the ArcSDE connection will be disconnected.
- To clear the workspace cache correctly in ArcMap: Remove all references to data in ArcMap that may be accessing the ArcSDE workspace and then run the Clear Workspace Cache tool to ensure the connection is disconnected.
- To clear the workspace cache correctly in a script: The call to ClearWorkspaceCache() should be the last call in your script making sure to remove all references to any objects that may be pointing to the ArcSDE workspace before making the call to ClearWorkspaceCache().
Syntax
Parameter | Explanation | Data Type |
in_data (Optional) |
The ArcSDE database connection file representing the ArcSDE workspace to be removed from the cache. Specify the path to the ArcSDE connection file that was used in running your geoprocessing tools in order to remove the specific ArcSDE workspace from the cache. Passing no input parameter will clear all ArcSDE workspaces from the cache. | Data Element; Layer |
Code Sample
The following Python window script demonstrates how to use the ClearWorkspaceCache function in immediate mode.
import arcpy
from arcpy import env
env.workspace = "c:/connectionFiles/Connection to gpserver.sde"
arcpy.ClearWorkspaceCache_management()
Sample showing how to disconnect from ArcSDE by clearing the ArcSDE workspace cache. Two methods are shown. 1. Disconnect from a specific connection by specifying the connection file name. 2. Disconnect from all connections by leaving the ArcSDE connection file parameter blank.
# Name: ClearWorkspaceCache_Example.py
# Description: Two examples: 1. Remove the specified ArcSDE workspace from the workspace cache,
# terminating the connection to ArcSDE from this client
# 2. Remove many ArcSDE workspaces from the workspace cache,
# terminating the connection to ArcSDE from this client for each workspace.
# Import system modules
import arcpy
from arcpy import env
# Set environment settings
env.workspace = "Database Connections\Connection to gpserver.sde" # Creates a connection to ArcSDE
fcList = arcpy.ListFeatureClasses() # Show that we are connected
print str(fcList) + "\n"
env.workspace = "" # Release hold on ArcSDE workspace created in previous step.
# Execute the Clear Workspace Cache tool
arcpy.ClearWorkspaceCache_management("Database Connections\Connection to gpserver.sde")
print arcpy.GetMessages() + "\n"
# Clear the Workspace Cache of multiple connections
# Set environment settings
# Connection 1
env.workspace = "Database Connections\Connection to gpServer.sde" # Creates a connection to ArcSDE
fcList = arcpy.ListFeatureClasses() # Show that we are connected
print str(fcList) + "\n"
# Connection 2
env.workspace = "Database Connections\Connection to ProductionServer.sde" # Creates a connection to ArcSDE
fcList = arcpy.ListFeatureClasses() # Show that we are connected
print str(fcList) + "\n"
# Connection 3
env.workspace = "Database Connections\Connection to TestServer.sde" # Creates a connection to ArcSDE
fcList = arcpy.ListFeatureClasses() # Show that we are connected
print str(fcList) + "\n"
env.workspace = "" # Release hold on ArcSDE workspace created in previous steps.
# Execute the Clear Workspace Cache tool
arcpy.ClearWorkspaceCache_management() # If you do not specify a connection, all ArcSDE workspaces will be removed from the Cache
print arcpy.GetMessages()