gpt4 book ai didi

c# - SqlException (0x80131904) 连接到 mdf 数据库

转载 作者:行者123 更新时间:2023-11-30 16:13:33 24 4
gpt4 key购买 nike

我有一个 C# 应用程序连接到 SQL Server .mdf 数据库文件,该文件位于我的应用程序目录的根目录中。该应用程序分发给公司中的其他用户。他们收到以下错误:

System.Data.SqlClient.SqlException (0x80131904): 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: 26 - Error Locating Server/Instance Specified)

并非所有用户都会遇到此错误。我假设这是一个安全错误。下面是我的连接字符串。知道是什么导致了这个问题,我该如何解决?

<add name="EditorConnectionString" 
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Resources.mdf;Integrated Security=True;User Instance=True;Persist Security Info=true;Connection Timeout=130"
providerName="System.Data.SqlClient" />

最佳答案

如果您在连接字符串中使用 AttachDbFileName=... 方法,则用于此操作的 SQL Server 必须 Express 版本。

此外,由于连接字符串包含 .\SQLEXPRESS 作为其 Data Source= 值,因此该 SQL Server Express 实例必须在本地运行在那台特定的机器上(这就是 .Data Source= 值中的意义)

关于c# - SqlException (0x80131904) 连接到 mdf 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21559372/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com