Connecting to Caché
Whether your application uses the object interface or the relational interface, it must first connect to Caché. To connect, the application must create a CacheConnection object and supply it with a connection string. To then open the connection, the application invokes the CacheConnection Open method:
Create a connection string. A typical connection string looks like the following:
string connectionString = "Server = localhost; Port=1972;" + "Log File = c:\\Phonebook.log; Namespace = USER;" + "Password = SYS; USER ID = _SYSTEM";Copy code to clipboard
Please note that the log file must be placed in a directory that the application is able to write to.
Initialize a CacheConnection object using the connection string and then open the connection using Open:
CacheConnection cnCache = new CacheConnection(connectionString); cnCache.Open();Copy code to clipboard
You can also use the ConnectDlg method to retrieve the connection string from the user at runtime. The method displays the standard Caché connection dialog boxes. The user then enters the connection string information into the boxes at runtime.
string connectionString = CacheConnection.ConnectDlg(); CacheConnection cnCache = new CacheConnection(connectionString); cnCache.Open();
The general format for the connection string is “Server = <server>; Port=<port>; Log File = <log>; Namespace = <namespace>; Password = <pwd>; User ID = <user>”