更新本地SQL Server数据库与ClickOnce部署数据库、SQL、Server、ClickOnce

2023-09-05 02:09:12 作者:你已进入我的世界就别糟蹋

我要建,这将使用一些设置和本地SQL Server的应用程序。我的问题是,当谈到时间更新应用程序;将设置或数据被覆盖?

I'm building an application which will use some settings and a local SQL Server. My question is, when it comes time to update the application; will the settings or data be overwritten?

如果我想在将来改变周围的一些表会发生什么事?

What happens if I want to change some tables around in the future?

推荐答案

坦率地说,我一直认为,处理数据的ClickOnce的方式是危险的。如果部署使用ClickOnce一个数据库,它把它在DataDirectory目录。然后,当你部署更新的应用程序,它复制转发数据库安装在应用程序的下一个版本的文件夹。但是,如果对数据库的修改,它会将其转发到文件夹+ \ pre,并提出在DataDirectory目录一个新的。如果你不知道你改变了它,它取代了也无妨。如果你这么多开放一个SQLCE数据库,并检查了数据结构的威猛的它得到部署。惊喜!

Frankly, I've always thought that ClickOnce's way of handling data is dangerous. If you deploy a database with ClickOnce, it puts it in the DataDirectory. Then when you deploy an update to the application, it copies the database forward to the folder where the next version of the app is installed. But if the database changes, it copies it forward to the folder + \pre, and puts a new one in the datadirectory. If you don't realize you changed it, it replaces it anyway. If you so much as open a SQLCE database and check out the data structures, wham it gets deployed. Surprise!

我觉得存储用户配置文件下在另一个文件夹中的数据更有意义,而且更安全。然后,您可以选择何时更新数据库。 这篇文章将展示如何将你的数据,因此它从ClickOnce的更新安全。

I think storing the data in another folder under the user's profile makes more sense, and is safer. Then YOU can choose when to update your database. This article will show how to move your data so it's safe from ClickOnce updates.

此外,如果你想更改您的数据库,可以使用SQL语句的话,如ALTER TABLE等。我创建了一个脚本,并将其部署为一个长字符串(在它回车),并有应用程序通过回车拆分的资源分开,由一个执行的语句之一。你得到的总体思路。

Additionally, when you DO want to make changes to your database, you can use SQL statements to do so, such as "ALTER TABLE" and so on. I've created a script and deployed it as one long string (with carriage returns in it) and had the application split the resource apart by carriage return and execute the statements one by one. You get the general idea.

一个评论有关用户设置 - 您可以通过用户界面编程改变这些(即给用户的能力)。但需要注意的是,如果你改变你的应用程序的证书和正在运行一个足够高版本的.NET(3.5,4),它不会给你一个问题本身,但它确实有一个不同的身份ClickOnce应用程序,并且用户设置不结转下次更新发布。出于这个原因,我也推出了配置数据我自己的XML文件,我将其存储在LocalApplicationData为好。

One comment about user settings -- You can change these programmatically via the UI (i.e. give the user the capability). But note that if you change the certificate of your application and are running a high enough version of .NET (3.5, 4), it won't cause you a problem per se, but it DOES have a different identity as a ClickOnce application, and the user settings are not carried forward when the next update is published. For this reason, I also rolled my own XML file for config data, and I store it in LocalApplicationData as well.