数据库未在客户端系统上运行的 C# Windows 窗体应用程序

标签 c# sql-server

我用 C# 开发了一个使用 SQL Server 数据库连接的 Windows 窗体应用程序。我在 .NET Framework 4.0 和 SQL Server 2008 R2 中开发它。我的应用程序使用的是应用程序根目录中名为 AG.mdf 的本地数据库。

这是我的连接字符串:

Data Source=.;AttachDbFilename=|DataDirectory|\\AG.mdf;Integrated     Security=True;User Instance=True 

我通过在 Visual Studio 安装程序模板中添加安装项目作为我的应用程序中的新项目来创建安装程序。我构建了安装项目,它为我创建了安装程序。我在我的用户系统上部署了应用程序,应用程序最初启动但突然弹出错误

Unhandled exception has occurred in your application. If you click continue, the application will ignore this message and attempt to continue. If you click quit, the application will close immediately.

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

附言:我在我的用户系统上也安装了 .NET Framework 4.0 和 SQL Server Compact Edition!

我应该退出编程吗:'(

最佳答案

我认为您可能会混淆 Express Edition 和 Compact Edition;它们真的很不一样。

精简版采用SDF 数据库文件,是一个嵌入式数据库,而不是单独的服务器。我不认为它可以直接与 MDF 一起工作 - 你可以 export an MDF to an SDF虽然。

SQLCE 不知道用户实例、集成安全性或数据库附件。我认为您需要直接在数据源部分中找到 SDF 文件的路径,但它需要是 SDF,而不是 MDF。

基本上,看起来您正在安装 Compact Edition,但随后为完整版/Express 版使用连接字符串和数据文件,这不太可能起作用。

关于数据库未在客户端系统上运行的 C# Windows 窗体应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16632416/

相关文章:

sql - 需要从 SQL 生成以下格式的 XML

html - 经典多选列表框 SQL 查询

sql - 为什么按主键分组的插入会抛出违反主键约束的错误?

C# WPF 如何将 .txt 文件的内容显示到列表框中?

c# - Web API 模型绑定(bind)

sql - 使用一个表中的不同记录将其与其他表的不同条目组合

sql-server - 如何计算出存储过程返回了多少数据?

c# - 如何测试 MongoDB 文档中的字符串字段不为空?

c# - Microsoft.ReportViewer.WinForms.V15 与 .NET Core 3.1 不兼容 - 如何在 WPF Core 中显示 RDLC?

c# - 为什么 C# && 和 ||运算符(operator)按照他们的方式工作?