Tuesday, August 7, 2012

Deploying Databases in Click Once Applications

I'm currently in the process of building an application that needs an sqlite database deployed with it for use inside the office. This was the first time I'd need to deploy a predefined database so I couldn't even run code to create the database on first run. I needed to deploy it with data. I could have deployed it as a .csv file which was then inserted into the sqlite db that is created during the first run but honestly, if I was going to deploy a csv for that then why bother? I might as well deploy the sqlite file with it right?

This was my first time deploying a clickonce application with a file so I had to do some digging around to figure out what the best practices for doing so might be. The first step was to include the sqlite db file in the build. Answer to that was found in the MSDN How to section for specifying which files are published in an application. The relevant part can be found under marking files as data.

  1. With a project selected in Solution Explorer, on the Project menu, click Properties.
  2. Click the Publish tab.
  3. Click the Application Files button to open the Application Files dialog box.
  4. In the Application Files dialog box, select the file that you wish to mark as data.
  5. In the Publish Status field, select Data File from the drop-down list.

Next comes the code to access the database. Keep in mind that what you've written probably follows a certain folder structure which needs to be maintained. 

Not a big deal but it's a two step process that needs a bit of poking and digging around to find. Unless you happen to use Mage. In which case you should be fine. 

No comments:

Post a Comment