Update SQLite Database in Background Task


  • Hi,

    I am working on a project in which i have a database with 2 tables. I am updating Table 2 based on the data available in Table 1 using background task because as per my requirement have to update table 2 periodically i.e every 1 hr.

    So, what i am doing is, i have started a background task of time trigger type, which is working perfectly well when i debug. But when i create package and deploy it than its not updating table 2.

    In Background task i am calculating network usage based on the sessionInfo available in table 1.

    Please help me in fixing this problem or suggest if you have any better way to achieve the goal.


    Its Windows 8.1 project.

    Rahul Jaiswal

    Friday, May 30, 2014 11:44 AM

All replies

  • In what way is it failing?

    Does the entire update path work if not called from a background task?

    Does the background task trigger fully? Does it try to update table 2 but fail? Or does it not get that far?

    How to debug a background task
    Guidelines and checklists for background tasks

    Saturday, May 31, 2014 3:06 AM
  • Hi,

    I have 2 table, table 1 hold connected network session information and using timer based background task i am updating table 2 with data usage information for the session in table 1. To get data usage, we are using       

    public async void Run(IBackgroundTaskInstance taskInstance)
                BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
                    taskInstance.Canceled += taskInstance_Canceled;
                    IReadOnlyList<ConnectionProfile> connectionProfileList = NetworkInformation.GetConnectionProfiles();
                    List<NetworkSessionInfo> processedNetworkSessionInfo = new List<NetworkSessionInfo>();
                    SqlConnection dbConn = new SqlConnection();
                    List<NetworkSessionInfo> dataNetworkTable = dbConn.GetNetworkSessionData();
                    foreach (var networkdata in dataNetworkTable)
                        var connectionProfile = connectionProfileList.FirstOrDefault(s => s.ProfileName.Split('.')[0].ToString() == networkdata.SSID);
                        if (connectionProfile != null)
                            DetailedNetworkUsage networkUsage = new DetailedNetworkUsage();
                            networkUsage.SSID = networkdata.SSID.ToString();
                            networkUsage.StartTime = networkdata.StartTime;
                networkUsage.EndTime = networkdata.EndTime;
                            networkUsage.Duration = (int)networkdata.EndTime.Subtract(networkdata.StartTime).TotalSeconds;
                            LocalDataUsage localUsage = await GetLocalDataUsage(connectionProfile, networkdata.StartTime, networkdata.EndTime);
                            networkUsage.ByteRecieved = localUsage.ByteRecieved;
                            networkUsage.ByteSent = localUsage.ByteSent;
                catch (Exception ex)
                    taskInstance.Progress = 100;
    My problem is, sometime table 2 get updated and sometimes not. I have implemented logger, came to know that background get called for the first time but later it never get called.

    Please help me any alternate way to achieve my objective.

    Rahul Jaiswal

    Tuesday, June 10, 2014 5:50 PM
  • Hi Rahul,

    It looks like you posted your reply on the wrong thread (along with a few others). Please try to keep threads coherent rather than posting the same question on multiple threads or multiple questions in one thread.

    Please let me know if you still need help with this and if you have any updates on what is going on. If you can provide a minimal sample on your OneDrive that demonstrates the problem that would be very helpful.


    Friday, June 20, 2014 9:21 PM
  • Hi Rob,

    Yes, i am still facing this issue. What i have figured out is that there is some issue in uninstall. After uninstalling App, i able to see my package name in lock screen app's setting. When i manually assign permission to some other app, than next time my App again asks me for permission and it works fine.

    Regards, Rahul Jaiswal

    Monday, June 23, 2014 11:31 AM
  • That is unrelated to this thread and a duplicate of something you posted to another thread. I assume that means you don't need help with the original question here.

    Please try to keep threads coherent rather than posting the same question on multiple threads or multiple questions in one thread.

    Monday, June 23, 2014 1:59 PM