0

We are developing a windows store 8.1 app, In that we implemented Offline data sync using Azure mobile Service(.net backend).

We are using Mobile service with On-Premise SQL Server with existing database using Code first migrations.

We have a USER table which stores user emailId and offlinePin in the database.

We also implemented AAD single sign on in the app. For all active directory users those who are going to use the app, we added their email ids to the User table with out offlinePin value.

In client app, We are calling the following line based on the user who log in to the app using AAD single sign on.

Declaration:

private IMobileServiceSyncTable<Users> usertable=  App.MobileService.GetSyncTable<Users>();

await usertable.PullAsync("SyncLoggedInUserInfo", usertable.Where(user => user.Email == App.UserEmail));

Now for the User who log in based on his/her mail Id we are pulling their information from USER table using above line.

If the logged in user don't have an offline pin then the app will prompt the user to create one and save that into the local SQLite USER table.

For updating the user offlinePin we are calling the following lines

var userInfo = await usertable.Where(x => x.Email == App.UserEmail).ToListAsync();
                if (userInfo .FirstOrDefault()!=null)
                {
                    var emp = userInfo .FirstOrDefault();
                    emp.OfflinePin = pinpswrdbx.Password;
                   await usertable.UpdateAsync(emp);
                }

After updating done we are pushing those changes to the Server.

await App.MobileService.SyncContext.PushAsync();

Here the issue is, the line calling for update the offline pin is not working, means

await usertable.UpdateAsync(emp); is not updating the respective employee information in local table. We are not getting any exception here, it's executing successfully but the offline pin column value is not updating with the user entered pin value.

It is happening only for the rows of data added directly on database and synced to local SQLite DB which are not created within the app, if the record is inserted/created with in the app then that data is updating and am able to push those changes to server as well.

I have to use the existing database and tables which already having data in it and the app should be able to update the data and push the changes back to the server DB.

Can anybody help me where I am missing or doing wrong?

6
  • From this description, it's hard to say exactly what's going wrong. When you step through the code, are you seeing a value populated for emp? Does it have all of the right properties? I recommend looking at the contents of the local database, perhaps using a command line tool like sqlite3 or the open source DB Browser for SQLite. For a Windows Store app, the database will be located in the following directory: C:\Users\<your-username>\AppData\Local\Packages\<App-name>\LocalState
    – lindydonna
    Aug 7, 2015 at 18:31
  • Yes I am able to see the data in local sqlite db, but the data is not getting update after calling updateasync() Aug 7, 2015 at 20:07
  • is it all fields not getting the update, or only your OfflinePin field?
    – phillipv
    Aug 7, 2015 at 20:49
  • also, please add a DelegatingHandler for logging or use Fiddler to track outgoing requests.
    – lindydonna
    Aug 8, 2015 at 3:00
  • Only OfflinePin is not updating, other fields in the table are updating. Aug 10, 2015 at 7:04

1 Answer 1

0

The problem is with the database, it is having case sensitive collation. I used fiddler to track what exactly the mobile service doing while pushing result to server, then I found that in the request URL all the stating letters of the table columns are automatically converting in to capital letters, but in database they are in small letters. May be due to this the data wasn't updated in database and roll backing in local DB as well.

To overcome this issue I had written the below line of code in DBContext class in mobile service project and did publish.

modelBuilder.Entity<User>().Property(p => p.Offlinepin).HasColumnName("offlinepin");

After this updating is working. I don't know why Mobile service did not show any error message when push failed instead it roll back the local values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.