You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS2022更新后发布C#程序遇SQL Server连接错误26求助

SQL Server连接错误26:实例定位失败排查求助

遇到以下重复出现的SQL Server连接错误,查阅大量同类问题后仍未找到原因:

provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified
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

相关代码

string connection = Properties.Settings.Default.SqlConnection;  

SqlConnectionStringBuilder builder = new() 
        { 
            ["Server"] = connection, 
            ["Database"] = "myDatabase", 
            ["Trusted_Connection"] = true 
        };  

using SqlConnection conn = new(builder.ConnectionString);  

try 
{ 
    conn.Open(); 
} 
catch (Exception ex) 
{ 
    throw;
} 
finally 
{ 
    conn.Close(); 
} 

配置文件设置

配置中存储的实例名为myServerName\myInstanceName,对应配置项:

<add name="TestSQLConnection.Properties.Settings.SqlConnection"  
     connectionString="Servername\SQL2012" /> 

问题现象

  • 程序本地运行正常,发布后普通用户触发上述错误
  • 以管理员身份在服务器运行发布后的程序可正常工作,且运行后其他用户能临时正常使用
  • 问题始于VS2022最新更新,此前版本无此问题;现在发布旧项目也会出现同样错误,但此前发布的同连接字符串的程序运行正常

已尝试的排查操作

  • 确认连接字符串无拼写错误
  • 确认服务器网络可达
  • 将连接字符串中的服务器名替换为IP地址
  • 检查SQL Server Browser服务处于运行状态
  • 在Server Configuration Manager中启用1433端口
  • 在连接字符串中显式添加1433端口
  • 测试此前发布的同类程序(同连接字符串),普通用户可正常使用
  • 修复Visual Studio 2022

更新信息

此问题明确与访问权限相关:将程序发布至旧应用已使用的文件夹即可正常运行,但新旧文件夹的安全设置无差异(用户/组权限完全相同)。

恳请告知进一步排查方向,此问题是否由VS更新导致?还是遗漏了某些细节?

内容的提问来源于stack exchange,提问作者user11272031

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 04:50:25