tags:

views:

218

answers:

3

I'm using ClickOnce to deploy my application. When the app runs the first time, if a db doesn't exist, it creates one.

Problem is, when I update, it removes the local database. Is there a way to tell it to ignore it?

+2  A: 

I imagine you're putting it in the applications directory... don't!

Put it in Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData or Environment.SpecialFolder.LocalApplicationData).

Philip Wallace
Are there any security concerns I need to take into account? Does the app by default have access to write to files outside the application folder?
Chu
By default, an application can write to ApplicationData and LocalApplicationData. Obviously, an admin or user can change the permissions on these folders at any time - but I think it is a "safe" assumption that you can write there.
Philip Wallace
+2  A: 

Don't include the database in the deployment. Implement your own db creation (using script) when the database isn't present.

rdkleine
I already am - it's not part of deployment, yet it gets removed if an update occurs.
Chu
+1. Good answer.. And be sure to put it in a place where it will be accessible, such as Environment.SpecialFolder.ApplicationData as answered by @Phillip
David Stratton
A: 

In the project's Publish options, under Application Files, is the database file's Publish status set to Data File?

CodeByMoonlight
The database file is actually accessed by a class project, so it doesn't show up in the Application Files area of the publish options.
Chu