Error while querying and loading from sterling database

Dec 14, 2011 at 5:06 AM
Edited Dec 14, 2011 at 5:07 AM

Hi,

I am facing an issue while performing queries or while loading a specific value from the sterling DB.
The application intermittently loads or queries a null value.The application seems to be working fine when both save as well as read operations is executed together, but causes an issue when it attempts to read from an already existing database having values. I am using the isolated storage driver for the application.(Working on Silverlight 4.0 and Sterling 1.5.4350.34367)

Regards,
Raju James

Code snippet used:

 


//Save operation
   for (int i = 0; i < 10; i++)
   {
       ChildDetails.Add(new RCChild { SlNo = i, PNo = 22, ID   =245, Name = "Raju", Birth = "12-2-1989", Sex = "Male", Grade = 2, ComnyCode = "RCCM1", CommunityName = "asd", CDCName "asdfe" });
   }

   foreach (var item in ChildDetails)
   {
       SterlingService.Current.Database.Save(item);
   }

//Read Operation
   foreach (var item in  SterlingService.Current.Database.Query<RCChild, int>())
   {
       ChildInfo.Add(item.LazyValue.Value);//Sometimes Loads null here

   }

   var loadValue = SterlingService.Current.Database.Load<RCChild>(1);//Sometimes Loads null here

Coordinator
Dec 14, 2011 at 12:12 PM

It doesn't look like you are flushing the database. That should happen after your save loop, or inside if there is a chance the program might terminate during the loop.

Dec 15, 2011 at 3:42 AM

Thanks for your prompt reply.

But I have upgraded the above code with the flush command and still seem to be facing the issue.

I am executing the code multiple times (writing to sterling and then reading it, then trying to read what is already written in sterling without saving anything new).

The code seems to read from the sterling DB when the read operation is accompanied by the save operation, but when the read executes as a standalone(ie trying to read from an already existing database), it occasionally returns a NULL.

This happens both in the query as well as the load operations.

Regards,

Raju James

Below is the new code:

 

        private void SaveToSterling_Click(object sender, RoutedEventArgs e)
        {
            List<RCChild> ChildDetails = new List<RCChild>();
            for (int i = 0; i < 15; i++)
            {
                ChildDetails.Add(new RCChild { SlNo = i, PNo = 22, ID = 245, Name = "Raju", Birth = "12-2-1989", Sex = "Male", Grade = 2, ComnyCode = "RCCM1", CommunityName = "asd", CDCName = "asdfe" });
            }

            foreach (var item in ChildDetails)
            {
                SterlingService.Current.Database.Save(item);//Sometimes Loads null here

            }
            SterlingService.Current.Database.Flush();

        }

            foreach (var item in SterlingService.Current.Database.Query<RCChild, int>())
            {
                ChildInfo.Add(item.LazyValue.Value);
            }

            var loadValue = SterlingService.Current.Database.Load<RCChild>(1);//Sometimes Loads null here

            dataGrid1.ItemsSource = ChildInfo;