Lesson 1: Compile the CustdbScripts.dll assembly with MobiLink references

.NET classes encapsulate synchronization logic in methods.

In this lesson, you compile a class associated with the CustDB sample database.

MobiLink database sample

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.

The CustdbScripts Assembly

In this section, you create a .NET class called CustdbScripts with logic to handle the ULCustomer upload_insert and download_cursor events.

MobiLink server API

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 or at a command prompt.

  • In Visual Studio, create a new Class Library and enter the CustdbScripts code. Link iAnywhere.MobiLink.Script.dll, and build the assembly for your class.

  • Put the CustdbScripts code in a text file and save the file as CustdbScripts.cs ( or CustdbScripts.vb for Visual Basic .NET). Using a command line compiler, reference iAnywhere.MobiLink.Script.dll and build the assembly for your class.

To create the CustdbScripts assembly using Visual Studio
  1. 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.

  2. 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
  3. Add a reference to the MobiLink server API.

    • From the Visual Studio Project menu, choose Add Existing Item.

    • Select iAnywhere.MobiLink.Script.dll in install-dir\Assembly\v2. In Visual Studio, from the Open menu, choose Link File. In Visual Studio 2005, from the Add menu choose Add Link.

  4. Right-click the CustdbScripts project and select the table Properties » General. For Visual Basic .NET, make sure that the text field Root Namespace is cleared of all text.

  5. 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
  1. Create a directory for the .NET class and assembly.

    This tutorial assumes the path c:\mldnet.

  2. 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
  3. Save the file as CustdbScripts.cs ( CustdbScripts.vb for Visual Basic .NET) in c:\mldnet.

  4. 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.

Further reading

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.