locked
Int type PK Issue with synchronization RRS feed

  • Question

  • Hello,

    I am using N tier architecture for synchronization for my mobile application. For now I am just using 1 table named Inventories in the bi-directional synchronization.

    Inventory table has PK as int type. Its not an auto-incrementing value. The way I manage PK is a lookup table that stores the latest value of the PK. So I do an insert on client that inserts some random PK value for the table and then before inserting anything on the server in my web service I use following code to look up the latest value and modify the datatable object:

    [WebMethod]
        public SyncContext ApplyChanges(SyncGroupMetadata groupMetadata, DataSet dataSet, SyncSession syncSession)
        {
          
            //now go to tblIdGenerator and grab the latest value from there
            SqlConnection serverConnection = new SqlConnection();
            serverConnection.ConnectionString = ConnString;
            serverConnection.Open();
            //Get the new ID value from the table
            SqlCommand getIDCmd = new SqlCommand();
            getIDCmd.CommandType = CommandType.Text;
            getIDCmd.Connection = serverConnection;
            getIDCmd.CommandText = "Select CurrentID from tblIDGenerator where ObjectType='Other'";
            object objInvID = getIDCmd.ExecuteScalar();
            _invID = System.Convert.ToInt32(objInvID);
            for (int count = 0; count < dataSet.Tables["InventoryTest"].Rows.Count; count++)
            {
                _invID = _invID + 1;
                DataRow row = dataSet.Tables["InventoryTest"].Rows[count];
                row["Inv_ID"] = _invID;
              
            }

            getIDCmd.CommandText = "Update tblIDGenerator set [CurrentID]=@InvID where [ObjectType]='Other'";
            getIDCmd.Parameters.AddWithValue("@InvID", _invID);
            getIDCmd.ExecuteNonQuery();
            serverConnection.Close();
            serverConnection.Dispose();

            return _serverProvider.ApplyChanges(groupMetadata, dataSet, syncSession);
        }

    However when I synchronize, I do not see this change in PK on the client. The client still stores the older value of PK even though I am using bi-directional synchronization.

    I would really appreciate if someone can point to what I am doing wrong here.

    Thanks

    Apurv


    • Moved by Max Wang_1983 Friday, April 22, 2011 8:10 PM forum consolidation (From:SyncFx - Microsoft Sync Framework Database Providers [ReadOnly])
    Monday, April 7, 2008 9:24 PM