Search code examples
c#.netintersystems-cache

How do I close a InterSystems.Data.CacheClient.dll database connection?


My connection to Caché doesn't close until the entire app \ IIS finishes.

For example, make a new project referencing InterSystems.Data.CacheClient.dll and try the following:

static void Main(string[] args)
{
    var connection = new CacheConnection("SERVER=10.10.10.41;PORT=1972;DATABASE=dsa-som-ting;PROTOCOL=TCP;UID=user;PWD=password;");

    connection.Open();      
    Console.ReadKey();  //open

    connection.Close();     
    Console.ReadKey(); //still open!

    connection.Dispose();       
    Console.ReadKey(); //still open!
}

The connection remains open the whole time, as I can see in the Caché portal: enter image description here

How do I close the connection??


Solution

  • .NET uses connection pooling to keep up to 100 connections open by default until an application ends.

    So even though you call connection.Close(), and it appears closed in your app, .NET keeps a copy of it open for use later when you call connection.Open() to save time.

    To alter the size of the pool use a connection string like:

    new CacheConnection("SERVER=10.10.10.41;PORT=1972;DATABASE=dsa-clb-def;PROTOCOL=TCP;UID=_System;PWD=sys;Max Pool Size=50;");