Previous Topic

Next Topic

Connecting to a c-treeACE SQL Database

A CtreeSqlConnection object represents a unique session to a c-treeACE SQL database. When you create an instance of CtreeSqlConnection, all properties are set to their initial values: the database name is set to “c-treeSQL”, the username and password are set to empty strings, the database server address is set to “localhost” and the service is set to “6597”. If the CtreeSqlConnection goes out of scope, it is not closed. Therefore, you must explicitly close the connection by calling the methods Close() or Dispose().

The following examples shows how to connect to a c-treeACE SQL database using the c-treeACE Data Provider and when the connection is no longer needed, close the connection.

.NET VB Example

Sub Connect()
   Dim conString As String = “User=ADMIN;Password=ADMIN;Database=ctreeSQL”
   Dim hConnection As New CtreeSqlConnection(conString)
   hConnection.Open()
   ... perform some operations ...
   hConnection.Close()
End Sub

.NET C# Example

void Connect()
{
   String conString = “User=ADMIN;Password=ADMIN;Database=ctreeSQL”;
CtreeSqlConnection hConnection = new CtreeSqlConnection(conString);
   hConnection.Open();
   ... perform some operations ...
   hConnection.Close();
}

.NET C++ Example

void Connect()
{
   String* conString = S“User=ADMIN;Password=ADMIN;Database=ctreeSQL”;
   CtreeSqlConnection* hConnection = new CtreeSqlConnection(conString);
   hConnection->Open();
   ... perform some operations ...
   hConnection->Close();
}

.NET Delphi Example

procedure Connect()
var
    conString : String;
    hConnection : CtreeSqlConnection;
begin
   conString := 'User=ADMIN;Password=ADMIN;Database=ctreeSQL';
   hConnection := CtreeSqlConnection.Create(conString);
   hConnection.Open();
   ... perform some operations ...
   hConnection.Close();
end;