This lesson provides the startup code to your application to connect to an UltraLite database.
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"> </td> <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> <br> <br> <table> <tr> <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> </tr> <tr> <td colspan=3> <input type="button" value="Synchronize" onclick="ClickSync();"> </td> </tr> </table> </form> |
Create a JavaScript file c:\tutorial\tutorial.js to provide application logic.
Add the following variables declaration to tutorial.js for the UltraLite Pod object :
var DB_mgr; var Connection; var Table; |
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 ); return; } dir = DB_mgr.directory; 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 != DB_mgr.SQLError.SQLE_ULTRALITE_DATABASE_NOT_FOUND ) { alert( "Error: cannot connect to database: " + ex.getMessage() ); return; } } |
Use the onload event handler to connect to the database when the application is started. Modify main.htm as follows:
Load tutorial.js by adding the following line immediately before the <body> tag:
<script src="tutorial.js"></script> |
Modify the <body> tag:
<body onload="Connect();"> |
Test your application.
Synchronize the UltraLite tutorial channel. The synchronization application should be connecting to the tutorial database.
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |