ArcGIS for Desktop

  • Documentation
  • Pricing
  • Support

  • My Profile
  • Help
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS for Desktop

A complete professional GIS

ArcGIS for Server

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Pricing
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

Help

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • More...

Clear Workspace Cache

  • Summary
  • Usage
  • Syntax
  • Code sample
  • Environments
  • Licensing information

Summary

Clears any enterprise geodatabase workspaces from the enterprise geodatabase workspace cache.

Usage

  • This tool only works with enterprise geodatabase workspaces.

  • This tool can be used to help disconnect idle enterprise geodatabase connections in a long-running application.

  • If you run the tool without specifying an Input data element, all enterprise geodatabase workspaces in the enterprise geodatabase workspace cache will be cleared. Specify the specific .sde file associated with the workspace you want to clear in order to clear a specific enterprise geodatabase workspace.

  • Note:
    Clearing an enterprise geodatabase workspace from the enterprise geodatabase workspace cache does not guarantee the connection to the enterprise geodatabase server will be disconnected. It will only ensure the geoprocessor object no longer has any hold on the enterprise geodatabase workspace that has been cleared. If any other process has references to this enterprise geodatabase workspace the connection will be maintained.
    • 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 enterprise geodatabase connection will be disconnected.
    • To clear the workspace cache correctly in ArcMap: Remove all references to data in ArcMap that may be accessing the enterprise geodatabase workspace and then run the ClearWorkspaceCache() 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 enterprise geodatabase workspace before making the call to ClearWorkspaceCache().

Syntax

ClearWorkspaceCache_management ({in_data})
ParameterExplanationData Type
in_data
(Optional)

The enterprise geodatabase database connection file representing the enterprise geodatabase workspace to be removed from the cache. Specify the path to the enterprise geodatabase connection file that was used in running your geoprocessing tools in order to remove the specific enterprise geodatabase workspace from the cache. Passing no input parameter will clear all enterprise geodatabase workspaces from the cache.

Data Element; Layer

Code sample

ClearWorkspaceCache Example (Python Window)

The following Python window script demonstrates how to use the ClearWorkspaceCache function in immediate mode.

import arcpy
arcpy.env.workspace = "c:/connectionFiles/Connection to gpserver.sde"
arcpy.ClearWorkspaceCache_management()
Clear Workspace Cache Sample

Sample showing how to disconnect from enterprise geodatabase by clearing the enterprise geodatabase 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 enterprise geodatabase connection file parameter blank.

# Name: ClearWorkspaceCache_Example.py
# Description: Two examples: 1. Remove the specified enterprise geodatabase workspace from the workspace cache, 
#                               terminating the connection to enterprise geodatabase from this client
#                            2. Remove many enterprise geodatabase workspaces from the workspace cache, 
#                               terminating the connection to enterprise geodatabase from this client for each workspace.

# Import system modules
import arcpy

# Set environment settings
arcpy.env.workspace = "Database Connections\Connection to gpserver.sde" # Creates a connection to enterprise geodatabase
fcList = arcpy.ListFeatureClasses() # Show that we are connected
print(str(fcList) + "\n")
arcpy.env.workspace = "" # Release hold on enterprise geodatabase 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
arcpy.env.workspace = "Database Connections\Connection to gpServer.sde" # Creates a connection to enterprise geodatabase
fcList = arcpy.ListFeatureClasses() # Show that we are connected
print(str(fcList) + "\n")

# Connection 2
arcpy.env.workspace = "Database Connections\Connection to ProductionServer.sde" # Creates a connection to enterprise geodatabase
fcList = arcpy.ListFeatureClasses() # Show that we are connected
print(str(fcList) + "\n")

# Connection 3
arcpy.env.workspace = "Database Connections\Connection to TestServer.sde" # Creates a connection to enterprise geodatabase
fcList = arcpy.ListFeatureClasses() # Show that we are connected
print(str(fcList) + "\n")
arcpy.env.workspace = "" # Release hold on enterprise geodatabase workspace created in previous steps.

# Execute the Clear Workspace Cache tool
arcpy.ClearWorkspaceCache_management() # If you do not specify a connection, all enterprise geodatabase workspaces will be removed from the Cache
print(arcpy.GetMessages())

Environments

  • Current Workspace

Licensing information

  • ArcGIS for Desktop Basic: Yes
  • ArcGIS for Desktop Standard: Yes
  • ArcGIS for Desktop Advanced: Yes

Related topics

  • An overview of the Workspace toolset

ArcGIS for Desktop

  • Home
  • Documentation
  • Pricing
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Insiders Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
© Copyright 2016 Environmental Systems Research Institute, Inc. | Privacy | Legal