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

SQL Anywhere 11.0.1 (中文) » MobiLink - 入门 » MobiLink 教程 » 教程:使用 .NET 同步逻辑

 

第 2 课:为事件指定类方法

有关 CustDB 示例数据库的详细信息,请参见建立 CustDB 统一数据库

上一课中创建的 CustdbScripts.dll 封装了 UploadInsert() 和 DownloadCursor() 方法。这些方法分别包含 ULCustomer upload_insert 和 download_cursor 事件的实现。

在本节中,可以用两种方法为表级事件指定类方法:

  1. 使用 MobiLink 同步插件。

    使用 Sybase Central 连接到 CustDB 数据库,将 upload_insert 脚本的语言更改为 .NET,然后指定 MLExample.CustdbScripts.UploadInsert 来处理事件。

  2. 使用 ml_add_dnet_table_script 存储过程。

    通过 Interactive SQL 连接到 CustDB 数据库并执行 ml_add_dnet_table_script,从而指定 MLExample.CustdbScripts.DownloadCursor 来处理 download_cursor 事件。

♦  为 CustdbScripts.uploadInsert() 预订 ULCustomer 表的 upload_insert 事件
  1. 使用 MobiLink 同步插件连接到示例数据库:

    1. 启动 Sybase Central。

    2. 在 [视图] 菜单中,确保已选择 [文件夹]。

    3. 在 [连接] 菜单中,选择 [使用 MobiLink 11 连接]。

    4. 在 [标识] 选项卡上,选择 [ODBC 数据源名称] SQL Anywhere 11 CustDB。

    5. 单击 [确定] 进行连接。

    6. 现在,Sybase Central 应在 MobiLink 11 插件下显示 CustDB 数据源。

  2. 将 ULCustomer 表 upload_insert 事件的语言更改为 .NET:

    1. 在左窗格中,打开 [同步表] 文件夹,然后选择 ULCustomer 表。在右窗格中,出现一个表级别脚本列表。

    2. 在右窗格中,打开 custdb 11.0 upload_insert 表脚本。在 [文件] 菜单中,选择 [语言],并将语言更改为 .NET。

  3. 输入用于 custdb 11.0 upload_insert 表脚本的 .NET 方法名称。

    1. 删除 upload_insert 表脚本的内容,以确保右窗格显示为空白。

    2. 在右窗格中键入以下内容:

      MLExample.CustdbScripts.UploadInsert
    3. 从 [文件] 菜单中选择 [保存] 以保存脚本。

  4. 退出 Sybase Central。

此步骤使用 Sybase Central 将 .NET 方法指定为 ULCustomer upload_insert 事件的脚本。

也可以使用 ml_add_dnet_connection_script 和 ml_add_dnet_table_script 存储过程。使用这些存储过程效率更高,特别是在使用大量 .NET 方法处理同步事件时。

请参见ml_add_dnet_connection_script 系统过程ml_add_dnet_table_script 系统过程

在下一节中,您将通过 Interactive SQL 连接到 CustDB 并执行 ml_add_dnet_table_script,从而将 MLExample.CustdbScripts.DownloadCursor 指派给 download_cursor 事件。

♦  为 ULCustomer download_cursor 事件指定 MLExample.CustdbScripts.DownloadCursor
  1. 使用 Interactive SQL 连接到示例数据库。

    1. 选择 [开始] » [程序] » [SQL Anywhere 11] » [Interactive SQL],或运行以下命令:

      dbisql
    2. 单击 [标识] 选项卡。

    3. 单击 [ODBC 数据源名称],然后键入 SQL Anywhere 11 CustDB。

    4. 单击 [确定] 进行连接。

  2. 在 Interactive SQL 中执行以下命令:

    CALL ml_add_dnet_table_script(
    'custdb 11.0',
    'ULCustomer',
    'download_cursor',
    'MLExample.CustdbScripts.DownloadCursor');
    COMMIT;

    以下是对每个参数的说明:

    参数 说明
    custdb 11.0 脚本版本。
    ULCustomer 同步表。
    download_cursor 事件名。
    MLExample.CustdbScripts.DownloadCursor 完全限定 .NET 方法。
  3. 退出 Interactive SQL。

在本课中,您指定了 .NET 方法来处理 ULCustomer 表级别事件。下一课将确保 MobiLink 服务器装载正确的类文件和 MobiLink 服务器 API。

进一步阅读

有关添加和删除同步脚本的详细信息,请参见添加和删除脚本

有关本课所用脚本的详细信息,请参见ml_add_dnet_connection_script 系统过程ml_add_dnet_table_script 系统过程