views:

977

answers:

2

Hi

I am using sql server 2005 ce framework 3.5 and attempting to use merge replication between my hand held and my sql server. When I run the code to synchronise it just seems to sit forever, and when I put a breakpoint in my code it never gets past the call to Synchronize().

If I look at the replication monitor in sql server, it gets to the point where it says the subscription is no longer synchronising and doesn't show any errors. Therefore I am assuming this to mean the synchronisation is complete.

http://server/virtualdirectory/sqlcesa35.dll?diag does not report any issues.

This is my first attempt at any handheld development, so I may have done something daft. However, sql server seems to be reporting a successful synchronisation.

Any help would be greatly appreciated as I have spent ages on this !

Here is my code.

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;
}

Thanks Loads, Cheryl

A: 

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 :)

Cheryl H
+1  A: 

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.

MusiGenesis