如何分发SQL Server应用程序?
我有一个使用 Visual Studio 2010 制作的非常简单的 C# Winforms 项目。它使用 SQL Express 2008。这是我第一次使用 SQL,所以我想要一种动手的方法来学习 SQL,而这个项目使我能够做到这一点。
我想将我的项目发布在我的网站上供人们查看。但是,我有存储过程、约束和其他东西(例如每个表中要放入哪些列),需要在程序第一次运行时进行设置。
有人告诉我可以使用 VS2010 的内置功能来制作 MSI 安装程序来完成此操作,但事实证明这非常复杂,我很快就放弃了。
对我来说,理想的解决方案是简单地压缩可执行文件并让它自动创建数据库、表、列、存储过程以及代码中的其他所有内容。这看起来相当原始,但也显得简单、非常直接。唯一的是,我不知道这是否可能。
我向 SO 社区提出的问题是,您会推荐什么?请记住,我不希望分发模型超过应用程序本身的复杂性,正如我所说,这是一个非常简单的组合类型项目。此外,如果您可以提供有关如何继续您的建议的示例和/或说明,我们也将不胜感激。
提前致谢!
I have a VERY simple C# Winforms project that I made using Visual Studio 2010. It uses SQL Express 2008. This is my first time using SQL, so I wanted a hands-on approach to learning SQL, and this project allowed me to do that.
I want to post my project on my website for people to see. However, I have stored procedures, constraints, and other things (such as what columns to put in each table) that need to be setup the first time my program is run.
I was told that this could be done using the built-in feature of VS2010 to make MSI installers, however this turned out to be very complex and I gave up on it quickly.
To me, the ideal solution would be to simply ZIP up the executable and have it automatically create the database, tables, columns, stored procedures, and everything else in-code. This seems rather primitive but it also seems simple and very direct. The only thing is, I don't know if this is possible.
My question for the SO community is what would you recommend? Please keep in mind that I do not want the distribution model to outweigh the complexity of my application itself, which as I stated is a very simple portfolio type project. Also if you could provide examples and/or instructions on how to proceed with your suggestion, that is much appreciated as well.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
作为一个简单的解决方案,您可以编写数据库脚本并将脚本文件包含在项目中(作为资源或作为单独的文件)。启动时,您的应用程序将检查数据库是否存在,如果不存在则运行脚本。
当然,这意味着 SQL Server 本身已经安装(或以某种方式与您的应用程序捆绑在一起)。
UPD。
创建脚本的最简单方法是 Management Studio 中的脚本生成向导(右键单击数据库,“任务”->“生成脚本”)。我希望这个向导可以在 Express 版本中使用。
有关示例,请参阅该线程从 .NET 代码执行脚本。
As an easy solution, you could script your database and include the script file in your project (as a resource or as a separate file). On startup your application will check whether the database exists and run the script if it doesn't.
Of course, this implies that SQL Server itself is already installed (or somehow bundled with your app).
UPD.
The easiest way to create a script is a script generation wizard from Management Studio (right-click on the database, Tasks -> Generate scripts). I hope, this wizard is available in Express edition.
See ths thread for an example of executing a script from .NET code.
您可能需要查看 Visual Studio数据库项目。
它们将帮助跟踪数据库中的所有对象并进行部署 相当容易,无需使用您自己的代码创建数据库和数据库对象。
You may want to look at Visual Studio database projects.
They will help keep track of all objects in the database and make deployment fairly easy without resorting to creation of databases and database objects with your own code.