Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.

For information on migrating to InterSystems IRIS, see Why Migrate to InterSystems IRIS?

Connecting a .NET Application to Caché

Complete the following steps to prepare your Visual Studio .NET project to use the CMP and then code a connection to Caché. Note that these steps are the same for both the CMP object and relational interfaces.

  1. Add the CMP dll InterSystems.Data.CacheClient.dll to your project's set of references. In Visual Studio, click Project–>Add Reference.... The DLL is in <cachesys>\Dev\dotnet\bin.

  2. Add the following using directives to your .NET code. These directives open CMP namespaces for use in the code.

    using InterSystems.Data.CacheTypes;
    using InterSystems.Data.CacheClient;   
  3. Add the following .NET Framework dlls to your project's set of references: System, System.Data. If you are using relational access and DataSets, you must also add a reference to System.XML.

  4. Add the following using directives to your .NET code. These directives open necessary .NET Framework namespaces for use in the code.

    using System; 
    using System.Data;

    System.Data is only required when using relational access through the CMP.

  5. Create the database connection by instantiating a CacheConnection object using an appropriate connection string.

    string cacheString = "Server=<Server>;" +
                          "Port=<port>;" +
                          "Namespace=<Namespace>;" +
                          "Password=<Password>;" +
                          "User ID=<UserName>;";
    CacheConnection cnCache = new CacheConnection(cacheString);       
  6. The database connection must be open in order to perform any database related operations, for example, executing a query, retrieving or creating and object, and so on. Use the Open method to open the connection.

  7. Close the database connection using the CacheConnection Close method.


In the above code <Server> refers to the machine hosting Caché. If you are running locally this is localhost. <port> refers to the Caché SuperServer. You can find this number using the Management Portal. At the top of this page click Management Portal–>About. Look under SuperServer Port. In a default Caché installation the port is 1972. If you installed Caché with minimal security, the <UserName> is _system and <Password> is SYS.

For more information about setting up the CMP, read Setting up the Caché Managed Provider in Using the Caché Managed Provider for .NET.

For more information about connecting a .NET application to Caché using the CMP, read Connecting to the Caché Database in Using the Caché Managed Provider for .NET.