2

I'm making a c++/Qt application. It connects to a small online database to find different information. I need to make sure that the application works offline. So I would like to do the following

On start up of application: - Check if internet connection is available - if available connect to online database, download database to local (for next time no internet is available) - if not available connect to the kocally stored version of the database

My problem is I can't find a simple solution how to "download" the database. The user will not update the database, so there is no need for syncing when online again, just the ability to download the newest version of the database, whenever online. It is a MS SQL server that the application uses.

My only idea for a solution is to have an SQLite db in the application, and then write a script that clears the SQLite database and then puts everything from the online server into it, but this requires that I write a script that goes through all of the databse. There must be a better solution. I'm also not sure how this solution should work if the database structure changes. A solution for this could just be to send out a update for the application if the structure changes with a new SQLite db with the new structure.

I tried searching for a solution, but I could not find anything that are simple. Since I don't neew syncing back and forth, I thought there must be a simple solution. Any help pointing me in the right direction is appreciated.

  • 4
    You could not find any simple solutions because it is not a simple task. SQL-Server and sqlite use different SQL dialects, and depending on your database structure it could be even impossible to migrate from one to the other. Anyway, do you use pure C++ or managed C++? – user1810087 Mar 13 '19 at 07:52
  • Would you allow the user to search arbitrary data or do you just need some specific excerpts? – Aconcagua Mar 13 '19 at 07:59
  • Maybe this can help : https://stackoverflow.com/questions/26057499/best-way-to-export-sql-server-database-to-sqlite-or-sql-server-compact – WaLinke Mar 13 '19 at 08:15
  • Can you set up a web server capable of serving the MDF of the online database so it can b downloaded as a file and attached to a local instance of sqlserver? – Caius Jard Mar 13 '19 at 08:46
  • IT does not have to be a SQLite solution, it can be any solution that would do the job, that was just my only idea. The user cannot search the database, I will have specific queries built in to my code for the application. I use Qt with c++, as far as I know it is unmanaged @Caius it has to be a MS SQL server, because that is what we used – Anders Nørløv Berthelsen Mar 13 '19 at 08:49
  • I didn't understand how your comment was related to mine. You have a server online, running SQL Server. This uses a file with an MDF extension. If you were **also** to set up a web server on the same machine, configure its home directory to be the folder where the MDF file is, then your app can download the MDF from the server over HTTP and attach it to a small local instance of SQLServer and query it that way.I'm proposing installing a web server as a way to cheaply and quickly get the entire database MDF file from the main server to the client device, where it can be used inside a local SQLS – Caius Jard Mar 13 '19 at 09:09
  • If you app has an internet connection, then it can download the MDF and cache it, then use the online database (more up to date data), or it can use the one it downloaded (faster querying). If it has no internet connection, it can use the last downloaded MDF – Caius Jard Mar 13 '19 at 09:10
  • downloading the mdf file sounds like an option. How can I make a c++ download the mdf? By the way users needs to be able to download the mdf file, even though they are not administrators of the database. They login with their windows authentication – Anders Nørløv Berthelsen Mar 13 '19 at 11:32
  • Also it should work on windows machines, but the user should not install any other software to make it run – Anders Nørløv Berthelsen Mar 13 '19 at 11:57

0 Answers0