Question
· Jul 31, 2018

Cache List Of Objects Connection

Hi Guys,

I' am using Cache Object Binding for .NET, our Cache Version is Cache for Windows (x86-64) 2010.2 (Build 454U).

How can I set the connection for Cache List of Objects? Here is my sample code.

//CACHEObject as my file generated from OBJECT BINDING

CACHEObject.ContainerImco containerImco = new CACHEObject.ContainerImco(cacheConnection);
CacheListOfObjects<CACHEObject.ContainerImco> lcontainerImco = new CacheListOfObjects<CACHEObject.ContainerImco>();

//Already tried this one but fails

//lcontainerImco.Connection.ConnectionString = "Server=" + Properties.Settings.Default.ServerName +
//                            "; Namespace=" + Properties.Settings.Default.Namespace +
//                            "; Password=" + Properties.Settings.Default.Password +
//                            "; User ID=" + Properties.Settings.Default.Username + ";";
//lcontainerImco.Connection.DynamicMode = true;
//lcontainerImco.Connection.Open();
 try
 {
          lcontainerImco.Add(containerImco);
          containerUpdate.containerImco = lcontainerImco;
}
catch (CacheObjException ex)
{ }
//lcontainerImco.Connection.Close();

Error is:

at InterSystems.Data.CacheTypes.CacheObject.get_Connection()
at InterSystems.Data.CacheTypes.CacheListOfObjects.Add(Object value)
at InterSystems.Data.CacheTypes.CacheListOfObjects`1.Add(T item)

when executing lcontainerImco.Add()

Database Structure:

Class ContainerUpdate Extends (%Persistent, %Populate, Container) [ ClassType = persistent, Inheritance = right ]
{

Property containerContent As ContainerContent;

Property documentNo As %String;

Property containerImco As list Of ContainerImco(SQLPROJECTION = "table/column", STORAGEDEFAULT = "array");

Property containerRemarks As %String;

Index classIndex [ Extent, Type = bitmap ];

}

Discussion (4)0
Log in or sign up to continue

Your code is quite difficult to read without proper styling. I recommend the 'Special Container'. We created a DLL from a c# class library generated from the .NET Object Binding Wizard and placed the DLL in our bin/ folder.

Assuming lcontainerImco.Connection is a CacheConnection object from 'Intersystems.Data.CacheClient'  and you have imported 'Intersystems.Data.CacheTypes'. The following should work.

CacheConnection CacheConnect = new CacheConnection();
CacheConnect.ConnectionString = server + "Port = " + connectionPort + "; " + "Namespace = USER; "
+ "Password = " + password + ";" + "User ID = " username + "; " + "pooling = false;";
CacheConnect.Open();

There is also a little known issue about certain special characters in the password causing parsing problems, which is identifiable from the following stack trace:

at InterSystems.Data.CacheClient.CacheADOConnection.createConnectionKeyString()\r\n   at
InterSystems.Data.CacheClient.CacheADOConnection.ParseConnectionStringInternal(String connectionStri
ng)\r\n   at InterSystems.Data.CacheClient.CacheADOConnection.set_ConnectionString(String value)\r\n

Bad characters in the password include pairing and delimiting characters eg.  equals sign, single-quotes and backslashes, pound sign symbol and not symbol. This was reported to WRC two years ago but never resolved, so we created a work-a-round solution.  

Refer to the documentation relevant to your Caché version for all the valid connection string parameters (I have linked the latest release) and be sure to wrap your connection in a try-catch structure.  

Hi Stephen,

I don't have any issue on connection, since same string is used in connecting to other Cache Objects that were binded to my .Net Studio.

This works perfectly fine.

                    CacheConnection cacheConnection = EstablishConnection();

                    CACHEObject.ContainerPosition currentPosition = new CACHEObject.ContainerPosition(cacheConnection);

                    if (message.currentPosition.locationIdentifier != null)
                    {
                        if (message.currentPosition.locationIdentifier != "")
                            currentPosition.locationIdentifier = message.currentPosition.locationIdentifier;
                    }
                    if (message.currentPosition.positionQualifier != null)
                    {
                        if (message.currentPosition.positionQualifier != "")
                            currentPosition.positionQualifier = message.currentPosition.positionQualifier;
                    }
                    if (message.currentPosition.positionSlot != null)
                    {
                        if (message.currentPosition.positionSlot != "")
                            currentPosition.positionSlot = message.currentPosition.positionSlot;
                    }
                    containerUpdate.currentPosition = currentPosition;

                     containerUpdate.Save();

                     containerUpdate.Close();

Where connection string is same with previous message.

                  private CacheConnection EstablishConnection()
                  {
                              CacheConnection cacheConnection = new CacheConnection();

                              cacheConnection.ConnectionString = "Server=" + Properties.Settings.Default.ServerName +
                                                "; Namespace=" + Properties.Settings.Default.Namespace +
                                                "; Password=" + Properties.Settings.Default.Password +
                                                "; User ID=" + Properties.Settings.Default.Username + ";";
                             cacheConnection.DynamicMode = true;
                            cacheConnection.Open();
                           return cacheConnection;
                    }

My problem is CacheListOfObjects threw an exception on Cache Disconnected but I find it hard to look for an example of setting the CacheListOfObjects connection. Already browsed the example located at InterSystems\Cache\dev\dotnet\samples.

Regards

Consider the line in C#

CACHEObject.ContainerImco containerImco = new CACHEObject.ContainerImco(cacheConnection);

Does this 'ContainerImco' object have a constructor that takes in a CacheConnection object?  Have you opened the connection?

From the error it looks like its failing when trying to get the connection. It seems a bit weird to have a collection of CacheConnection objects.