如何在应用程序安装中部署数据库
我有一个使用 Sql Server Express Edition 来存储数据的应用程序。我有一个数据库,里面有 8-10 个表。我有 mdf 和 ldf 文件。现在我想在其他计算机上安装我的应用程序,然后如何使用我的安装文件部署我的数据库(假设其他计算机已经安装了 Sql Server)。我可以使用我的 mdf 和 ldf 文件吗,或者我需要在安装应用程序期间以编程方式再次创建我的数据库和表。
我是新手,请指导一下。我正在使用.Net Framework 4.0和Visual Studio Professional Edition。
I have an application which uses Sql Server Express Edition to store data. I have a database with 8-10 tables in it. I have mdf and ldf file with me. Now i want to install my application in some other computer, then how to deploy my database with my installation files (assuming the other computer already have Sql Server with them). Can i use my mdf and ldf files, or i need to create my database and tables again programatically during installation of my Application.
I am a newbie, please guide me. I am using .Net framework 4.0 and Visual Studio Professional Edition.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SQL Server Express 在进程外运行,因此您的应用程序无法控制数据文件。您必须通过数据语句、复制或其他方式将应用程序数据提交到 SQL Server,然后 SQL Server 来决定如何处理它们。
您可以通过
AttachDBFilename
连接字符串直接向 SQLS Express 提交 .mdf,我还没有尝试过。如果您使用 SQL Server Compact 等嵌入式数据库,您将能够将数据包含在您的应用程序中。这是否是更好的解决方案取决于您对数据库执行的其他操作。
SQL Server Express runs out-of-process, so your application does not control the data files. You have to submit your application data to SQL Server via data statements, replication, or whatever, and SQL Server gets to decide what to do with them.
You may be able to submit an .mdf directly to SQLS Express via an
AttachDBFilename
connection string, I have not tried this.If you used an embedded database like SQL Server Compact you would be able to include the data along with your application. Whether this is a better solution depends on what else you are doing with your database.