none
How to implement an online/offline mode with an SQL database in a Windows Forms application? RRS feed

  • Question

  • Hello,

    I've got a Windows Forms application that displays tables from an online database and allows the user to view and make changes to the database. I have the connection string to the online database in the project settings, and when a Windows Form loads, it loads the data from the corresponding database tables into the TableDataGridView objects, and some others.

    I'd like to be able to add an offline mode, so that when the user is away from the internet, they can still see the database as it was when they were last connected, and make changes as they please. When they reconnect to the internet, their changes will be synced to the main online database.

    I'm pretty inexperienced with this sort of thing, and I'm not sure how I would go about making the offline mode. Currently, as soon as the user isn't connected to the internet, the program throws errors when it tries to load windows as it's trying to load data from the online database tables to fill in the TableDataGridView objects with data, and it can't.

    Is there some way to save a snapshot of the online database as the user goes offline, and then have the connection string point to that snapshot instead, and then somehow have it sync when they come back online?

    Please let me know if you need any more information!

    Thanks so much for taking the time to read my post!

    Sunday, January 20, 2019 11:59 PM

All replies

  • Hello,

    Look at Microsoft Sync Framework. One code sample of many code samples on the web.

    Our applications use assertion and prompts to go on or offline. Data for each user is specific and downloaded automatically for them. In the field w/o a Internet connection they do work, come back to the office and press a sync button as they don't want auto sync. So part of this is saying is know your business requirements, work with them. If there cases where ther remote database may have changes that need to be pushed you could have a procedure that alerts users that data that they are interacting with has changed and ask them to perform a sync. I've found that in my line of business that users don't care for auto sync'ing outside of mandatory ones.

    Also consider what happens when a snapshot is being made and a Internet connection is lost.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Monday, January 21, 2019 1:25 AM
    Moderator
  • Hi Karen,

    Thanks for your help! I'll look into it and make sure I get a better idea of what is needed.

    Thanks

    Monday, January 21, 2019 5:29 AM
  • Hi plynch77,

    If the reply is helpful for you, could you please mark it as answer, it will be beneficial to other communities who have the similar issue.

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 23, 2019 2:33 AM
    Moderator