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

SQL Anywhere 10.0.1 » MobiLink - Getting Started » Tutorial: Using .NET Synchronization Logic » Lesson 1: Compile the CustdbScripts.dll assembly with MobiLink references

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

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

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

  4. Right-click the CustdbScripts project and select the table Common Properties > General. Make sure that the text box called 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:"%sqlany10%\Assembly\v1\iAnywhere.MobiLink.Script.dll" c:\mldnet\CustdbScripts.cs

    For Visual Basic .NET, type:

    vbc /out:c:\mldnet\custdbscripts.dll /target:library /reference:"%sqlany10%\Assembly\v1\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.