我有一个使用 VS 2008 (C#) 和 SQL Server Express 2008 构建的 WinForm 应用程序,当前部署在测试用户 PC 上。
我需要对数据库结构进行修改(添加字段、表等),我想知道在用户 PC 上分发更改的最佳方法是什么(不会丢失用户数据)。
根据我到目前为止所学到的知识,我需要将更改写入脚本文件。 但是,分发脚本文件而不在 SQL Server Management Studio 中手动运行脚本文件的最佳方法是什么? 您有什么建议的自动分配方法吗? 我必须编写自己的更新应用程序吗?
我当前使用 ClickOnce 来分发 EXE 文件中的更改。 当您必须使用新版本对数据库进行更改时,ClickOnce 是否仍然是可行的解决方案?
TIA
I have a WinForm application built with VS 2008 (C#) and SQL Server Express 2008 that is currently deployed on test users PC.
I have modifications to do on the database structure (add fields, tables, etc.) and I wonder what's the best method to distribute the changes on the users PC (without loosing the users data).
From what I've learned so far, I will need to write the changes in a script file. But what's the best method to distribute the script files without running them manually in the SQL Server Management Studio? Is there any automatic distribution method you suggest? Do I have to write my own update application?
I currently use ClickOnce to distribute the changes in the EXE file. Is ClickOnce still a viable solution when you have to do changes in the database with the new version?
TIA
发布评论
评论(3)
有很多方法可以做到这一点 - 要么以某种方式构建自己的自制版本(例如,我们当前将数据库更改脚本打包到 DLL 中作为嵌入式资源,并拥有一个引擎,可以在安装时在客户端计算机上运行这些脚本) /或更新时间),或者您可以查看现成的 .NET 产品,例如 Red-Gate SQL Packager 可以为您节省大量时间和精力。
There are lots of ways you can do this - either build up your own homegrown version somehow (e.g. we are currently packaging database change scripts into a DLL as embedded resources, and have an engine that'll run those on the client machine at install and/or update time), or you can look at readily available .NET products like Red-Gate SQL Packager which can save you lots of time and effort.
您可以在启动时编写应用程序以从应用程序文件夹中读取脚本文件并执行它。 您可以让脚本在完成后更新数据库中的值,以防止其再次运行。
您可以将新的脚本文件部署为内容,应用程序将在下次启动时执行它,从而升级您的数据库
You could write your application on startup to read a script file from the application folder and execute it. You could have the script update a value in the database once its done to prevent it from being run again.
You can deploy the new script file as content and the application will execute it on the next startup, upgrading your database
您可以调用 MSSQL 附带的 osql 或 sqlcmd。
或者您可以使用 SMO 运行数据库更改脚本。 请参阅 此博客是如何完成的。
You can either call osql or sqlcmd which ship with MSSQL.
Or you can use SMO to run your database change scripts. See this blog how it's done.