UltraLite ActiveX User's Guide
Understanding UltraLite ActiveX Development
Connecting to an UltraLite database
The following procedure uses a ULConnectionParms object to connect to an UltraLite database.
For more information about connecting to an UltraLite database using a ULConnectionParms object, see CreateDatabaseWithParms method and OpenConnectionWithParms method.
To connect to an UltraLite database using ULConnectionParms
Create a ULDatabaseManager object.
You should create only one DatabaseManager object per application. This object is at the root of the object hierarchy. For this reason, it is often best to declare the DatabaseManager object global to the application.
' eMbedded Visual Basic Dim DatabaseMgr As ULDatabaseManager Set DatabaseMgr = CreateObject("UltraLite.ULDatabaseManager")
// JScript var DatabaseMgr; DatabaseMgr = new ActiveXObject( "UltraLite.ULDatabaseManager" );
Declare a ULConnection object.
Most applications use a single connection to an UltraLite database, and keep the connection open all the time. For this reason, it is often best to declare the ULConnection object global to the application.
' eMbedded Visual Basic Dim Connection As ULConnection
// JScript var Connection;
Create a ULConnectionParms object.
' eMbedded Visual Basic Dim LoginParms As ULConnectionParms Set LoginParms = CreateObject("UltraLite.ULConnectionParms")
// JScript var LoginParms; LoginParms = new ActiveXObject("UltraLite.ULConnectionParms");
Set the required properties of the ULConnectionParms object. For example, the following code specifies the location of the database on the Windows CE device as \tutorial\tutorial.udb.
' eMbedded Visual Basic LoginParms.DatabaseOnCE = "\tutorial\tutorial.udb"
// JScript LoginParms.DatabaseOnCE = "\\tutorial\\tutorial.udb";
Using the following properties, you must specify a schema file for CreateDatabaseWithParms or a database file for OpenConnectionWithParms. For information about additional properties, see Properties.
Keyword | Description |
---|---|
SchemaOnDesktop | The path and filename of the UltraLite schema. SchemaOnDesktop is required when using CreateDatabaseWithParms on Windows desktop operating systems. SchemaOnCE has precedence over SchemaOnDesktop. |
SchemaOnCE | The path and filename of the UltraLite schema on Windows CE. This is a required parameter when using CreateDatabaseWithParms for CE. |
DatabaseOnDesktop | The path and filename of the UltraLite database. This is a required parameter when using OpenConnectionWithParms on Windows desktop operating systems. DatabaseOnCE has precedence over DatabaseOnDesktop. |
DatabaseOnCE | The path and filename of the UltraLite database on Windows CE. This is a required parameter when using OpenConnectionWithParms for CE. |
Open a connection to the database.
CreateDatabaseWithParms and OpenConnectionWithParms return an open connection as a ULConnection object. Each method takes a single ULConnectionParms object as its argument.
The following code fragment attempts to connect to an existing database. If the database does not exist, the OpenConnectionWithParms method returns an error. This causes CreateDatabaseWithParms to create a database using the specified schema file.
' eMbedded Visual Basic On Error Resume Next Set Connection = DatabaseMgr.OpenConnectionWithParms(LoginParms) if Err.Number <> 0 then Set Connection = DatabaseMgr.CreateDatabaseWithParms(LoginParms) End If
// JScript DatabaseMgr.ErrorResume = true; Connection = DatabaseMgr.OpenConnectionWithParms(LoginParms); if ( DatabaseMgr.LastErrorCode != 0 ) { Connection = DatabaseMgr.CreateDatabaseWithParms(LoginParms); }