UltraLite applications must connect to a database before carrying out operations on the data in it. This section describes how to connect to an UltraLite database.
The following properties of the ULConnection object govern global application behavior.
Commit behavior By default, UltraLite.NET applications are in AutoCommit mode. Each Insert, Update, or Delete statement is committed to the database immediately. You can use ULConnection.BeginTransaction to define the start of a transaction in your application. See Managing transactions.
User authentication You can change the user ID and password for the application from the default values of DBA and sql by using methods to grant or revoke connection permissions. Each UltraLite database can define a maximum of four user IDs. See Authenticating users.
Synchronization A set of objects governing synchronization is accessed from the Connection object. See Synchronization in UltraLite applications.
Tables UltraLite tables are accessed using methods of the Connection object. See Accessing and manipulating data with the Table API.
Commands A set of objects is provided to handle the execution of dynamic SQL statements and to navigate result sets. See Accessing and manipulating data using SQL.
See ULConnection class.
Each ULConnection and all objects created from it should be used on a single thread. If your application requires multiple threads accessing the UltraLite database, each thread requires a separate connection. For example, if you design your application to perform synchronization in a separate thread, you must use a separate connection for the synchronization and you must open the connection from that thread.
Declare a ULConnection object.
Most applications use a single connection to an UltraLite database and leave the connection open. Multiple connections are only required for multi-threaded data access. For this reason, it is often best to declare the ULConnection object as global to the application.
Open a connection to an existing database.
UltraLite applications must deploy an initial database file or the application must include code to create the database file. The initial database file can be created by using Sybase Central or the command line utilities provided with UltraLite.
You can specify connection parameters either as a connection string or using the ULConnectionParms object. The following example illustrates using the ULConnectionParms object to connect to an ULtraLite database namedmydata.udb.
ULConnectionParms parms = new ULConnectionParms(); parms.DatabaseOnDesktop = "mydata.udb"; conn = new ULConnection( parms.ToString() ); conn.Open();
The code samples in this chapter are in Microsoft C#. If you are using one of the other supported development tools, you must modify the instructions appropriately.
|Discuss this page in DocCommentXchange.
Send feedback about this page using email.
|Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1|