使用ClickOnce部署更新本地SQL Server数据库 [英] Updating local SQL Server databases with ClickOnce Deployment

查看:172
本文介绍了使用ClickOnce部署更新本地SQL Server数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个将使用某些设置和本地SQL Server的应用程序。我的问题是,何时更新应用程序?设置或数据会被覆盖吗?



如果我以后想改变一些表格,会发生什么?

解决方案>

坦白说,我一直认为ClickOnce处理数据的方式是危险的。如果您使用ClickOnce部署数据库,则将其放在DataDirectory中。然后当您将更新部署到应用程序时,它会将数据库转发到安装了下一个应用程序版本的文件夹。但是,如果数据库更改,它会将其复制到文件夹+ \pre,并在datadirectory中放入一个新的文件夹。如果你没有意识到你改变了它,它会取代它。如果您打开一个SQLCE数据库并查看数据结构,那么它将被部署到 。惊喜!



我认为将数据存储在用户配置文件下的另一个文件夹中更有意义,更安全。那么您可以选择何时更新数据库。 本文将会展示如何移动数据,以便ClickOnce更新是安全的。



此外,当您想要更改数据库时,可以使用SQL语句,例如ALTER TABLE等。我创建了一个脚本,并将其部署为一个长字符串(带回车符),并且应用程序将资源拆分为回车符并逐个执行该语句。你得到一般的想法。



关于用户设置的一个注释 - 您可以通过UI以编程方式更改这些内容(即给予用户能力)。但是请注意,如果您更改应用程序的证书并运行足够高的.NET版本(3.5,4),则不会造成您本身的问题,但它具有与ClickOnce应用程序不同的身份,并且下次更新发布时,用户设置不会转发。因此,我也滚动了我自己的XML文件配置数据,并将其存储在LocalApplicationData中。


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?

解决方案

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!

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.

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.

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.

这篇关于使用ClickOnce部署更新本地SQL Server数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆