• <GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • Data Sources
    • Synchronization
    • CSPro Statements and Functions
    • Text Templates
    • Templated Reporting System
    • HTML, Markdown, and JavaScript Integration
    • Action Invoker
      • Overview
      • Execution Environments
      • Security, Resource Management, and Formatting Options
      • Base Actions
      • Application Namespace
      • Clipboard Namespace
      • Data Namespace
        • Data Action Invoker Namespace
        • Data.close Action
        • Data.contains Action
        • Data.countCases Action
        • Data.deleteCase Action
        • Data.getCurrentCase Action
        • Data.open Action
        • Data.query
        • Data.queryCases Action
        • Data.queryKeys Action
        • Data.readCase Action
        • Data.writeCase Action
      • Dictionary Namespace
      • File Namespace
      • Hash Namespace
      • Localhost Namespace
      • Logic Namespace
      • Message Namespace
      • Network Namespace
      • Path Namespace
      • Settings Namespace
      • Sqlite Namespace
      • Sync Namespace
      • System Namespace
      • UI Namespace
    • Appendix
  • <CSEntry>
  • <CSBatch>
  • <CSTab>
  • <DataManager>
  • <TextView>
  • <TblView>
  • <CSFreq>
  • <CSDeploy>
  • <CSPack>
  • <CSDiff>
  • <CSConcat>
  • <Excel2CSPro>
  • <CSExport>
  • <CSIndex>
  • <CSReFmt>
  • <CSSort>
  • <ParadataConcat>
  • <ParadataViewer>
  • <CSCode>
  • <CSDocument>
  • <CSView>
  • <CSWeb>

Data.close Action

Format
CS.Data.close(dataId := ...)
ArgumentDescriptionTypes / Required
dataIdThe resource ID returned by Data.open, or a dictionary name.number, string
recommended
Description
The Data.close action closes a data source previously opened using Data.open.
The data source is identified using dataId. If specified as a string, it references the data source that is connected to a dictionary that is part of an application. If specified as a number, it is processed as a resource ID returned by Data.open. This typically references non-application data sources. While optional, this should generally be specified explicitly. (If there is only one data source open, the resource ID can be calculated implicitly.)
If the data source previously opened was a dictionary that is part of an application, this action does not actually close the data source, as it is "owned" by the application, but instead ends the Action Invoker's ability to access this data source using dataId.
For data sources not connected to application dictionaries, the data source is closed and additional actions or queries cannot occur until opening the data source again.
This action is similar to the CSPro logic function close.
Return Value
The action returns undefined.
Exceptions
The action throws an exception if any of its arguments are not specified in a valid form, or if:
  • The data source ID is not valid.
  • There is an error closing the data source.
Even if there is an error closing the data source and an exception is thrown, the data source ID is no longer valid following this action.
Example (JavaScript)
let dataId;

try {
   
// open the Popstan Census example data
    dataId = CS.Data.open({
        connection: 
"Popstan Census.csdb"
    });

   
// display the number of cases
    const numCases = CS.Data.countCases({
        dataId: dataId
    });

    print(`Popstan Census contains ${numCases} cases.`);
}
catch (error) {
    print(
"Error interacting with data source: " + error);
}
finally {
   
// close the data source
    if( dataId != undefined ) {
        CS.Data.close({
            dataId: dataId
        });
    }
}
See also: Data Action Invoker Namespace, Data.open Action, Close Function