Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 12.0.0 (Français) » UltraLite - M-Business Anywhere Programming » Tutorial: A sample application for M-Business Anywhere


Lesson 4: Add startup code to your application

This lesson provides the startup code to your application to connect to an UltraLite database.

 ♦  Add content to your application
  1. Add the following content to main.htm, immediately before the <a> tag:

    <form name="form">
    <br><td> ID: </td>
        <td> <input type="text" name="ID" size="10"> </td>
    <br><td> Given Name: </td>
        <td> <input type="text" name="GivenName" size="15"> 
    <br><td> Surname: </td>
        <td> <input type="text" name="Surname" size="50"> </td>
    <br><td> Street: </td>
        <td> <input type="text" name="Street" size="20"> </td>
    <br><td> City: </td>
        <td> <input type="text" name="City" size="20"> </td>
    <br><td> Phone: </td>
        <td> <input type="text" name="Phone" size="12"> </td>
        <td> <input type="button" value="Insert" 
             onclick="ClickInsert();"> </td>
        <td> <input type="button" value="Next" 
             onclick="ClickNext();"> </td>
        <td> <input type="button" value="Prev" 
             onclick="ClickPrev();"> </td>
        <td colspan=3>
        <input type="button" value="Synchronize" 
  2. Create a JavaScript file c:\tutorial\tutorial.js to provide application logic.

  3. Add the following variables declaration to tutorial.js for the UltraLite Pod object :

    var DB_mgr;
    var Connection;
    var Table;
  4. Add the following function to tutorial.js to connect to the tutorial database:

    function Connect()
        var     dir;
        var     open_parms;
        var     browser = navigator.platform;
        DB_mgr = CreateObject( "iAnywhere.UltraLite.DatabaseManager.Tutorial" );
        if( DB_mgr == null ) {
         alert( "Error: cannot create database manager: " + DB_mgr.sqlCode );
        dir =;
        open_parms = "con=tutorial;" + "file_name=" + dir + "\\tutorial.udb";
        try {
     Connection = DB_mgr.reOpenConnection( "tutorial" );    
         if( Connection == null ) {
         Connection = DB_mgr.openConnection( open_parms );
        } catch( ex ) {
         if( DB_mgr.sqlCode != 
             alert( "Error: cannot connect to database: " + ex.getMessage() );
  5. Use the onload event handler to connect to the database when the application is started. Modify main.htm as follows:

    1. Load tutorial.js by adding the following line immediately before the <body> tag:

      <script src="tutorial.js"></script>
    2. Modify the <body> tag:

      <body onload="Connect();">
  6. Test your application.

    Synchronize the UltraLite tutorial channel. The synchronization application should be connecting to the tutorial database.