Locking up after SQL Server Mobile Merge Replication

Hi,

I am trying perform merge replication programatically between SQL Server 2005 and SQL Server Mobile. Using the following code (note i have changed some of the names for the purpose of the post <*> etc:

          private void Synchronise()
        {
            SqlCeReplication repl = new SqlCeReplication();
            //repl.
            repl.InternetUrl = @"
//sqlcesa30.dll">http://<hostname>/<db_Name>/sqlcesa30.dll";
            repl.Publisher = @"<hostname>";
            repl.PublisherDatabase = @"<db_Name>
            repl.PublisherSecurityMode = SecurityType.NTAuthentication;
            repl.Publication = @"<db_Name>";
            repl.Subscriber = @"<db_Name";

            repl.SubscriberConnectionString = @"Data Source=""\Program Files\<app_name>\<Mobile_db_name>.sdf"";Max Database Size=128;Default Lock Escalation =100;";
            try
            {
                repl.Synchronize();
            }
            catch (SqlCeException ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                repl.Dispose();
            }
        } 

I find after i invoke the replication by pressing the a button that the merge works fine. I can load a form and read the new data from the database.

My problem is, if i create a new row for one of the tables in the mobile database that when i try to insert it using a generated table adapter that the application locks up, so much so that i have to reset the device completely.

If i dont perform the merge replication and add a row and insert it into the DB it works fine.

So i guess my questions are:
1. Why cant i insert a row into the sql server mobile db without it locking up after performing merge repliction , am i forgetting to clean something up
2. i noticed a max database size in the SubscriberConnectionString above of 128. looking on the device the db size is 244k before syncrhonisation... is this causing the problem

Any help would be appreciated.

Thnx,
pdns




Answer this question

Locking up after SQL Server Mobile Merge Replication

  • srinivas nch

    Hi ,

    I would like to get your advice in an issue that I am facing regarding merge replication.

    The flow is like:

    1) User enter his login name and password.

    2) Host_name is set as the login name that the user enters.

    3) Based on the HOST_NAME property after filtering user gets the records relevent only to him

    (Differnet subscriber may use same mobile device).

    4) He make some changes in the local sdf according to the business logic.

    5) The application Syncs with server on the next login session.

    My issue is when I am trying to run the application in emulator exactly at the sdf updating part the application terminates.

    Error mess: Connection to Remote Device has been lost.....

    If I execute the same sql insert query it works om the local sdf and master database.

    Emulator used where Pocket PC 2003 SE and Windows Mobile 6 classic emulator.

    I have installed 1) Visual Studio 2005 SP 1 2) net compact framework SP2.

    When I comment all the code related to Sync ,application works witout any issue.

    And the same application works in my "I mate kjam".

    The code that I use is given below:

    ==========================================================================

    public void Sync(string hostname, int newsub) // Parameters for HOSTNAME and flag to denote new user or existing //user.

    {

    SqlCeReplication repl = new SqlCeReplication();

    repl.InternetUrl = @"http://231.000.000.211/Merge/sqlcesa30.dll";

    repl.Publisher = @"SERVER";

    repl.PublisherDatabase = @"Merge";

    repl.PublisherSecurityMode = SecurityType.DBAuthentication;

    repl.PublisherLogin = @"sa";

    repl.PublisherPassword = @"password";

    repl.Publication = @"Merge";

    repl.Subscriber = @"MergeSub";

    repl.HostName = hostname;

    repl.SubscriberConnectionString = @"Data Source=""\Program Files\Merge.sdf"";Max Database Size=128;Default Lock Escalation =100;";

    try

    {

    if (newsub == 0)

    {

    if (File.Exists(@"\Program Files\Merge.sdf"))

    {

    File.Delete(@"\Program Files\Merge.sdf");

    }

    repl.AddSubscription(AddOption.CreateDatabase);

    repl.Synchronize();

    repl.Dispose();

    MessageBox.Show("newuser sync Done");

    }

    else

    {

    if (!File.Exists(@"\Program Files\Merge.sdf"))

    {

    repl.AddSubscription(AddOption.CreateDatabase);

    repl.Synchronize();

    repl.Dispose();

    MessageBox.Show("FirstSync Done");

    }

    else

    {

    repl.Synchronize();

    repl.Dispose();

    MessageBox.Show("SameuserSync Done");

    }

    }

    =================================================================================

    Please advise......



  • Kenneth MacDonald

    There is no need to post your repro - calling endupdate does not work properly in Beta 2.  I sat at MEDC in May trying to get this same thing to work when Neil Enns (Product Mgr for VS2005) leaned over my shoulder and explained that this was not working yet in Beta 2.  Merge replication typically adds 3 GUID columns to your table and the update/insert statement didn't know how to handle this in Beta 2.

    You need to update to the RTM version of VS2005 to get the changes to your dataset to update in the SQL Mobile database.

    -Darren Shaffer
    .NET Compact Framework MVP

  • Rob Pearmain

    ok thanks for clarifying that Darren .
     
    Laxmi my appologies for not checking my email until now, i had been busy completing my thesis which utilised VS .NET 2005, the .NET Framework 2.0 and .NET CF 2.0, SQL Server 2005 CTP, SQL Server Mobile, Merge Replication, Web Services and the list goes on..... However my experiences have all be good  and the support from these forums has been great too.  I look forward to using the RTM version Big Smile

    Thanks,
    pdns


  • steveo942

    Hi,

       Can you please post a small repro program to try out the same thing locally.

    Thanks,
    Laxmi NRO, MSFT, SQL Mobile, Microsoft Corporation

  • bowman

    Max Database Size = 128 means it is 128 MB. So your concern about size is ruled out.

    Coming to the locking up, we have not come across any.  After a look at the first glance, I really doubt how your input InternetURL is working. 

    It should be:
    repl.InternetUrl = @"http://<hostname>/<db_Name>/sqlcesa30.dll";

    But yours is,
    repl.InternetUrl = @"
    //sqlcesa30.dll">http://<hostname>/<db_Name>/sqlcesa30.dll";

    Can you try with a correct URL.

    Thanks,
    Laxmi NRO, MSFT, SQL Mobile, Microsoft Corporation


  • JulianMarin

    Thanks and glad to hear the news that you want to migrate to RTM version.

    Thanks,

    Laxmi Narsimha Rao ORUGANTI, MSFT, SQL Mobile, Microsoft Corporation



  • Dr Zombie

    Hi,

        You seem to be using VS 2005 Beta 2.

        There are couple of things changed in the data designed code generation.

        Can you please let us know whether you are still able to reproduce the same with RTM.

    Thanks,
    Laxmi NRO, MSFT, SQL Mobile, Microsoft Corporation


  • Sara Tahir

    Hi Laxmi,

    Firstly thnx for the reply :) .. secondly my apollogies it seems i had a cut and paste error in the first post.  The correct synchronise method has the rep.InternetUrl in the correct format you suggested.

    To give an example of where the problem is ocurring the call sequence is as follows:

    1. A generated strongly typed datatable that was created with the dataset
    designer has been dragged on as a DataGrid from the datasources
    (Tools->show data sources). In this example an ItemDataTable.
    2. Selected the smart tag on the datagrid and press "generate data forms" which adds the New button and a Summary and Edit details form.

    ...
    Synchronise();
    ...
    //User navigates to the ItemForm which contains the item datagrid from step1
    //And the data that was replicated is shown withouth problems.


    //So the user then decides to create a new item
    private void NewMenuItem_Click(object sender, EventArgs e)
    {
         itemBindingSource.AddNew();
         Cursor.Current = Cursors.WaitCursor;
         itemEditViewDialog = CARSMR.UI.ItemDetailDialog.Instance(); 
         itemEditViewDialog.Closed += new EventHandler(itemEditViewDialog_Closed);
         itemEditViewDialog.SetDataSource(this.itemBindingSource); 
         Cursor.Current = Cursors.Default;
         itemEditViewDialog.ShowDialog();
    }


    //Once the user has pressed ok after adding the new items details
    //this is executed
    void itemEditViewDialog_Closed(object sender, EventArgs e)
    {
                this.Save();
                ItemDetailDialog.Instance().Closed -= new EventHandler(itemEditViewDialog_Closed);
    }


    //Which calls this
    private void Save()
    {
                this.itemBindingSource.EndEdit();
                Cursor.Current = Cursors.WaitCursor;

    //And within this call is where it locks up in the designer generated code on the update statement
                this.itemTableAdapter.Update((CARSMR_DBDataSet)this.itemBindingSource.DataSource);
                Cursor.Current = Cursors.Default;
    }


    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:2.0.50215.44
    ....
    // locking up within this code below

    public virtual int Update(CARSMR_DBDataSet dataSet) {
                return this.Adapter.Update(dataSet, "Item");
    }


    Now at this stage it just sits there with the cursor turning very very slowly.  pressing the windows start drop down takes ages to pop up. 

    So what puzzels me is that it is reading the data that is replicated from the database fine but as soon as it wants to write a new record to it after replicating, then it just locks up and the device needs to be reset.

    Some further playing around found:
    -=- If i close my application and then launch it again before trying to add an item then it works.

    So after writing this i am thinking that since closing my app then opening it again allowed it to write to the db again (not ideal from a users perspective ;) ) it might  be the database tables/rows are being locked or read-only by the replication process, SQL Server Client Agent ...   I am not really an expert with the process that merge replication uses.. but do my thoughts ring any bells anyone






  • Shamrox

    Hi Laxmi,

    I would be happy to try to reproduce it but i dont have RTM :(

    Thanks,
    pdns

  • Locking up after SQL Server Mobile Merge Replication