.NET classes encapsulate synchronization logic in methods.
In this lesson, you compile a class associated with the CustDB sample database.
SQL Anywhere ships with a SQL Anywhere sample database (CustDB) that is already set up for synchronization, including the SQL scripts required to drive synchronization. The CustDB ULCustomer table, for example, is a synchronized table supporting a variety of table-level events.
CustDB is designed to be a consolidated database server for both UltraLite and SQL Anywhere clients. The CustDB database has a DSN called SQL Anywhere 11 CustDB.
In this section, you create a .NET class called CustdbScripts with logic to handle the ULCustomer upload_insert and download_cursor events.
To execute .NET synchronization logic, the MobiLink server must have access to the classes in iAnywhere.MobiLink.Script.dll. iAnywhere.MobiLink.Script.dll contains a repository of MobiLink server API for .NET classes to use in your .NET methods.
For more information about the MobiLink server API for .NET, see MobiLink server API for .NET reference.
When compiling the CustdbScripts class, you must include this assembly to make use of the API. You can compile your class using Visual Studio .NET or at a command prompt.
To create the CustdbScripts assembly using Visual Studio .NET
Start a new Visual C# or Visual Basic .NET Class Library project.
Use CustdbScripts for the project Name and enter an appropriate path. This tutorial assumes the path c:\mldnet.
Enter the CustdbScripts code.
For C#, type:
namespace MLExample { class CustdbScripts { public static string UploadInsert() { return("INSERT INTO ULCustomer(cust_id,cust_name) values (?,?)"); } public static string DownloadCursor(System.DateTime ts, string user ) { return("SELECT cust_id, cust_name FROM ULCustomer WHERE last_modified >= '" + ts.ToString("yyyy-MM-dd hh:mm:ss.fff") +"'"); } } } |
For Visual Basic .NET, type:
Namespace MLExample Class CustdbScripts Public Shared Function UploadInsert() As String Return("INSERT INTO ULCustomer(cust_id,cust_name) values (?,?)") End Function Public Shared Function DownloadCursor(ByVal ts As System.DateTime, ByVal user As String) As String Return("SELECT cust_id, cust_name FROM ULCustomer " + _ "WHERE last_modified >= '" + ts.ToString("yyyy-MM-dd hh:mm:ss.fff") +"'") End Function End Class End Namespace |
Add a reference to the MobiLink server API.
Right-click the CustdbScripts project and select the table Common Properties » General. Make sure that the text field Root Namespace is cleared of all text.
Build CustdbScripts.dll.
From the Build menu, choose Build CustdbScripts.
This creates CustdbScripts.dll in C:\mldnet\CustdbScripts\CustdbScripts\bin\Debug.
To create the CustdbScripts assembly at a command prompt
Create a directory for the .NET class and assembly.
This tutorial assumes the path c:\mldnet.
Using a text editor, enter the CustdbScripts code.
For C#, type:
namespace MLExample { class CustdbScripts { public static string UploadInsert() { return("INSERT INTO ulcustomer(cust_id,cust_name) values (?,?)"); } public static string DownloadCursor(System.DateTime ts, string user ) { return("SELECT cust_id, cust_name FROM ULCustomer where last_modified >= '" + ts.ToString("yyyy-MM-dd hh:mm:ss.fff") +"'"); } } } |
For Visual Basic .NET, type:
Namespace MLExample Class CustdbScripts Public Shared Function UploadInsert() As String Return("INSERT INTO ULCustomer(cust_id,cust_name) values (?,?)") End Function Public Shared Function DownloadCursor(ByVal ts As System.DateTime, ByVal user As String) As String Return("SELECT cust_id, cust_name FROM ULCustomer " + _ "WHERE last_modified >= '" + ts.ToString("yyyy-MM-dd hh:mm:ss.fff") +"'") End Function End Class End Namespace |
Save the file as CustdbScripts.cs ( CustdbScripts.vb for Visual Basic .NET) in c:\mldnet.
Compile the file using the following command.
For C#, type:
csc /out:c:\mldnet\custdbscripts.dll /target:library /reference:"%sqlany11%\Assembly\v2\iAnywhere.MobiLink.Script.dll" c:\mldnet\CustdbScripts.cs |
For Visual Basic .NET, type:
vbc /out:c:\mldnet\custdbscripts.dll /target:library /reference:"%sqlany11%\Assembly\v2\iAnywhere.MobiLink.Script.dll" c:\mldnet\CustdbScripts.vb |
The CustdbScripts.dll assembly is generated.
For more information about the MobiLink server API for .NET, see MobiLink server API for .NET reference.
For more information about .NET methods, see Methods.
Send feedback about this page via email or DocCommentXchange | Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 |