WiX:您如何更新数据库?
在我的 WiX 项目中,我有一个文件数据和一个 SQL 脚本,用于创建数据库、创建/更改表、插入/更新行等。所有脚本分为三个部分,并通过 SqlScript 元素执行。我使用 ContinueOnError="no"
但如果前面的脚本执行成功,则不会回滚。我可以将所有脚本包装在事务中并使用 try/catch 块吗?有机会处理 WiZ 的 catch 事件吗?您对制作此类安装程序有何建议?
In my WiX project I have a file data and a SQL scripts which create db, create/alter tables insert/update rows, etc. All scripts are separated into three parts and are executed via SqlScript element. I use ContinueOnError="no"
but if the previous script was executed successfully it don't be rollbacked. Can I wrap all scripts in transaction and use try/catch blocks? Is there a chance to handle catch event from WiZ? What can you advise to make such kind of the installer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们不使用 Wix SQL 扩展,我们运行自定义操作来完成我们需要的工作。
安装时,我们使用自定义操作首先备份数据库,然后运行正确的升级脚本(基于当前数据库的版本),并在需要时将数据库恢复到备份作为升级的回滚操作。
卸载时,我们备份数据库,将其删除(有条件地基于用户输入),并在卸载过程中出现任何问题时进行恢复。
We don't use Wix SQL extension, we run custom actions to do the job we need.
On install, we use custom actions to first backup the database, then run the right upgrade scripts (based on version of current database), and if needed restore the database to the backup as a rollback action of the upgrade.
On uninstall, we backup the database, delete it (conditionally based on user input), and restore if anything goes wrong during the uninstall.
Wix 不以这种方式处理 SQL 脚本。
我相信你的选择相当有限。
安装前创建数据库备份并在安装失败时恢复它。除非您确定数据大小始终很小,否则这可能不应该成为安装程序的自动化部分。
提供回滚 SQL 脚本,以便在安装失败时排序并运行。根据您需要的数据库更改类型,这可能是一个真正的痛苦。
我不知道有任何安装程序工具包甚至尝试在大型安装中自动执行数据库回滚。有太多的变量需要考虑。 (例如,其余非数据库安装需要多长时间以及可能对数据库连接超时产生的影响)
Wix does not handle SQL scripts that way.
I believe your choices are fairly limited.
Create a database backup before installation and restore it on install failure. Unless you know for certain that the data size will always be small this probably should not be an automated part of the installer.
Provide rollback sql scripts to be sequenced and run in case of install failure. This can be a real pain in the ass to get correct depending on the types of DB changes you need.
Offhand I am unaware of any installer tool kit that even attempts to automate database rollbacks as part of a larger install. There are just too many variables to account for. (e.g. how long the rest of the non-DB installation takes and the affect that could have on database connection timeout)