1

我正在使用 SQL Server 2005 CE 框架 3.5 并尝试在我的手持设备和我的 SQL Server 之间使用合并复制。当我运行代码进行同步时,它似乎永远存在,当我在代码中放置断点时,它永远不会超过对 S​​ynchronize() 的调用。

如果我查看 sql server 中的复制监视器,它会说订阅不再同步并且不显示任何错误。因此,我假设这意味着同步已完成。

http://server/virtualdirectory/sqlcesa35.dll?diag没有报告任何问题。

这是我第一次尝试任何手持式开发,所以我可能做了一些愚蠢的事情。但是,SQL Server 似乎报告了成功的同步。

任何帮助将不胜感激,因为我已经为此花费了很多时间!

这是我的代码。

const string DatabasePath = @"SD Card\mydb.sdf";
var repl = new SqlCeReplication
               {
                   ConnectionManager = true,
                   InternetUrl = @"http://server/virtualdirectory/sqlcesa35.dll",
                   Publisher = @"servername",
                   PublisherDatabase = @"databasename",
                   PublisherSecurityMode = SecurityType.DBAuthentication,
                   PublisherLogin = @"username",
                   PublisherPassword = @"password",
                   Publication = @"publicationname",
                   Subscriber = @"PPC",
                   SubscriberConnectionString = "Data Source=" + DatabasePath
               };
try
{
    Cursor.Current = Cursors.WaitCursor;
    if (!File.Exists(DatabasePath))
    {
        repl.AddSubscription(AddOption.CreateDatabase);
    }
    repl.Synchronize();
    MessageBox.Show("Successfully synchronised");
}
catch (SqlCeException e)
{
    DisplaySqlCeErrors(e.Errors, e);
}
finally
{
    repl.Dispose();
    Cursor.Current = Cursors.Default;
}
4

2 回答 2

1

Another thing you can do to speed up the Synchronize operation is to specify a db file path that is in your PDA's main program memory (instead of on the SD Card as in your example). You should see a speed improvement of up to 4X (meaning the Sync may take only 25% as long as it's taking now).

If you're running out of main program memory on your PDA, you can use System.IO.File.Move() to move the file to the SD Card after the Synchronize call. This seems a bit strange, I know, but it's much faster to sync to program memory and copy to the SD card then it is to sync directly to the SD card.

于 2008-11-11T05:28:36.203 回答
0

I have since discovered that it was just taking a long time to copy the data to the physical disk. Although the sql server replication had completed, it was still copying the data to the sd card.

I identified this by reducing the amount of tables I am replicating and I got a more immediate response (well another error but unrelated to this issue).

Thanks anyway :)

于 2008-11-10T17:08:59.770 回答