Database connection caching

Previously if you wanted to avoid the overhead of Database.Connect() in a web service application you had to write some sort of connection pool. In 9.2 this is no longer required as the SDK itself caches connections.  The requirements are that:

  • the previous connection must be Disposed,
  • the subsequent connection must have the same Database Id, work group server name  and trusted user.

Sample Code

private static Database getDatabase(string user = null)
{
    Database database = new Database();
    database.WorkgroupServerName = "local";
    database.Id = "L1";
    if (user != null)
    {
        database.TrustedUser = user;
    }
    _watch.Reset();
    _watch.Start();
    database.Connect();
    _watch.Stop();

    Console.WriteLine(_watch.ElapsedMilliseconds);

    return database;
}


private static void connectDatabase()
{
    string trustedUser = "itu_tadmin";
    using (var db = getDatabase(trustedUser))
    {
    }

    using (var db2 = getDatabase(trustedUser))
    {
    }

    using (var db2 = getDatabase(trustedUser))
    {
    }
}



static void Main(string[] args)
{
    TrimApplication.TrimBinariesLoadPath = @"Your bin folder";
    TrimApplication.Initialize();
    TrimApplication.SetAsWebService("c:\\junk");

    connectDatabase();

}

Demonstration

Written on December 7, 2017