如何使用本地SQL Server数据库为应用程序创建安装软件包 [英] How to create install package for app using local SQL server database

查看:131
本文介绍了如何使用本地SQL Server数据库为应用程序创建安装软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个小应用程序,以了解有关SQL的更多信息并尝试使用Entity Framework.第一次执行时,我的应用程序在本地创建数据库,然后打开现有数据库.到目前为止,一切都很好-它在安装了SQL Server 2017的笔记本电脑上运行良好.

I wrote a small app to learn more about SQL and experiment with Entity Framework. On first execution, my app creates the database locally, and after that opens the existing database. So far, so good - it works pretty well on my laptop, which has SQL Server 2017 installed.

我尝试将程序集复制到台式机上,尽管未安装SQL Server,该操作也按预期工作.

I tried copying the assemblies to my desktop machine and that also worked as expected, though SQL Server was not installed.

但是,当我尝试将程序集复制到另一台笔记本电脑时,该应用程序将无法运行.我看到的例外是:

But when I tried copying the assemblies to another laptop, the app would not run. The exception I saw was:

与网络相关或特定于实例的错误发生在 建立与SQL Server的连接.找不到服务器或 无法访问.验证实例名称正确,并且 SQL Server配置为允许远程连接. (提供者:SQL 网络接口,错误:52-无法找到本地数据库 运行时安装.验证SQL Server Express是否已正确安装 并启用了本地数据库运行时功能.)

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The Server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a local Database Runtime Installation. Verify SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)

所有计算机都是Windows10.(台式计算机上安装了Visual Studio 2019是否重要?)

All machines are Windows 10. (Is it significant that the desktop machine has Visual Studio 2019 installed?)

我似乎在这里找不到可以说明我问题的帖子. (我可能对查询的措辞不好...)

I can't seem to find a post here which speaks to my problem. (I'm probably not phrasing my query well...)

无论如何,我不希望其他用户需要安装SQL Server(Express或其他).我需要在安装中包括什么?

Anyway, I don't want other users to be required to install SQL Server (Express, or otherwise). What do I need to include in my installation?

是否可以通过使用ClickOnce部署(又称为发布向导)来自动执行或多或少的操作?还是我需要使用Wix代码构建.msi?

Can it be done more-or-less automatically by using ClickOnce deployment (a.k.a. Publishing Wizard)? Or do I need to build an .msi with Wix code?

SQLite是否是更好的选择?我的应用程序的用户将不会共享数据库;每个人都有自己的.

Is SQLite a better option for this? Users of my app will not be sharing databases; each will have their own.

我在这篇文章中提到了SQL Server Compact Edition:

I have seen mention of SQL Server Compact Edition in this post: ASP.NET MVC - Switching from SQL Server Express to Compact Edition - Connection Issue, but when I tried to run this down, it seemed like this is no longer available from Microsoft. And I believe I'm already using SQL Server Express (looks like this is confirmed by the error message, above)...

目前,我已经通过使用ClickOnce部署解决了此问题.在短期内,我想更改安装,以将依赖项(.NET和SQL运行时)包含在安装程序包中,而不是在安装时进行下载.

At present I have worked around this problem by using ClickOnce deployment. In the near term, I would like to change the installation to include the dependencies (.NET & SQL runtimes) in the setup package, rather than downloading them at install-time.

但是我不知道SQLite是否会是一个更好的长期解决方案...我对SQLServer赞赏的一件事是,我可以使用SQLServer Management Studio来获取除应用程序之外的数据库,因此我可以验证应用程序已完成.我也认为这对用户来说是一件好事,因为如果应用出现问题,他们将始终有第二个选择来获取数据.

But I wonder if SQLite would be a better long-term solution... One thing I have appreciated about SQLServer is that I can use SQLServer Management Studio to get at the database apart from the app, so I can validate what the app has done. I also think this is a good thing for users, as they will always have a second option for getting their data, if something goes wrong with the app.

SQLite是否提供任何类似于SQLServer Management Studio的工具来访问数据库?

Does SQLite provide any tool similar to SQLServer Management Studio for accessing the database?

推荐答案

SQLite是更好的选择,因为它是嵌入式数据库.这意味着它是您应用程序的一部分,不需要其他设置.它适用于存储未共享的每个用户的数据.

SQLite is a better option as it is an embedded database. This means that it is a part of your application and doesn't require additional setup. It works well for storing per-user data that is not shared.

https://www.sqlite.org/whentouse.html

SQLite仅需要其程序集即可进行部署.

SQLite only requires its assemblies for deployment.

.net应用程序的SQLite部署

这篇关于如何使用本地SQL Server数据库为应用程序创建安装软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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