C# 将应用程序发布到远程服务器时连接到SQL时出现问题

C# 将应用程序发布到远程服务器时连接到SQL时出现问题,c#,asp.net,sql-server,iis,tcp,C#,Asp.net,Sql Server,Iis,Tcp,应用程序将加载,但当应用程序尝试连接到SQL时,加载需要一段时间,然后返回一个错误。使用数据链接(.udl文件)测试连接属性时,成功。该应用程序在我的本地计算机上也运行良好。我搜索了所有地方,设置都很好,网络管理员验证了防火墙,所有设置都是正确的。我错过了什么 我注意到它在错误中提到了名称管道,但是,这不应该成为TCP吗 SQLConnectionString.NetworkLibrary = "dbmssocn"; 这是我对连接字符串的方法: public string GetReachou

应用程序将加载,但当应用程序尝试连接到SQL时,加载需要一段时间,然后返回一个错误。使用数据链接(.udl文件)测试连接属性时,成功。该应用程序在我的本地计算机上也运行良好。我搜索了所有地方,设置都很好,网络管理员验证了防火墙,所有设置都是正确的。我错过了什么

我注意到它在错误中提到了名称管道,但是,这不应该成为TCP吗

SQLConnectionString.NetworkLibrary = "dbmssocn";
这是我对连接字符串的方法:

public string GetReachoutConnectionString()
    {
        SqlConnectionStringBuilder SQLConnectionString = new SqlConnectionStringBuilder();
        SQLConnectionString.TypeSystemVersion = "Latest";
        SQLConnectionString.NetworkLibrary = "dbmssocn";
        SQLConnectionString.DataSource = "10.10.xxx.xx,1433";
        SQLConnectionString.InitialCatalog = "cat";
        SQLConnectionString.UserID = "xxx";
        SQLConnectionString.Password = "xxx";
        SQLConnectionString.MultipleActiveResultSets = true;
        SQLConnectionString.ApplicationName = "Website";

        return SQLConnectionString.ConnectionString;
    }
这就是我得到的错误:

[Win32Exception(0x80004005):异常 找不到网络路径]

[SqlException(0x80131904):与网络相关或特定于实例的 建立与SQL Server的连接时出错 找不到服务器或无法访问服务器。请验证实例 名称正确,并且SQL Server配置为允许远程访问 连接。(提供程序:命名管道提供程序,错误:40-无法 打开与SQL Server的连接)]

System.Data.SqlClient.SqlInternalConnectionDS..ctor(DbConnectionPoolIdentity 标识、SqlConnectionString连接选项、SqlCredential 凭证、对象providerInfo、字符串newPassword、SecureString newSecurePassword、布尔重定向edUserInstance、SqlConnectionString userConnectionOptions,SessionData重新连接SessionData, DbConnectionPool池,字符串accessToken,布尔值 applyTransientFaultHandling)+1394
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions 选项、DbConnectionPoolKey poolKey、对象poolGroupProviderInfo、, DbConnectionPool池,DbConnection owningConnection, DbConnectionOptions用户选项)+1120
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool 池、数据库连接所有者对象、数据库连接选项、, DbConnectionPoolKey-poolKey,DbConnectionOptions-userOptions)+70
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject、DbConnectionOptions用户选项、DbConnectionInternal 旧连接)+964
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject、DbConnectionOptions用户选项、DbConnectionInternal 旧连接)+114
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 WaitForMultipleObjectStimOut,布尔型 allowCreate,仅布尔值EchkConnection,DbConnectionOptions 用户选项,DbConnectionInternal&connection)+1631
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource
1重试,DbConnectionOptions
用户选项,DbConnectionInternal&connection)+117
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection,TaskCompletionSource
1重试,DbConnectionOptions 用户选项、DbConnectionInternal oldConnection、DbConnectionInternal& 连接)+267
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection 外部连接,数据库连接工厂连接工厂, TaskCompletionSource
1重试,DbConnectionOptions用户选项)+318
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource
1 重试)+211
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 重试)+393 System.Data.SqlClient.SqlConnection.Open()+122
System.Data.Common.DbDataAdapter.FillInternal(数据集, DataTable[]datatables,Int32 startRecord,Int32 maxRecords,字符串 srcTable,IDbCommand,CommandBehavior行为)+177
System.Data.Common.DbDataAdapter.Fill(DataSet数据集,Int32 startRecord、Int32 maxRecords、字符串srcTable、IDbCommand、, 命令行为)+182
System.Data.Common.DbDataAdapter.Fill(数据集,字符串 srcTable)+123
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments 参数)+2964
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e)+369 System.Web.UI.WebControls.ListControl.PerformSelect()+43
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound()+139 System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e)+36
System.Web.UI.Control.PreRenderRecursiveInternal()+107
System.Web.UI.Control.PreRenderRecursiveInternal()+204
System.Web.UI.Control.PreRenderRecursiveInternal()+204
System.Web.UI.Control.PreRenderRecursiveInternal()+204
System.Web.UI.Control.PreRenderRecursiveInternal()+204
System.Web.UI.Control.PreRenderRecursiveInternal()+204
System.Web.UI.d_u249.MoveNext()+1400 System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务 任务)+13847892
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+61
System.Web.Util.WithIncachellableCallbackTaskWaiter.GetResult()+32
System.Web.UI.d_u523.MoveNext()+9283


我发现,web.config文件中有一个杂项连接字符串导致程序返回该错误。当我测试不同的连接方法时,VisualStudio自动添加了它。我把它删掉了,它成功了。我的连接字符串没有问题,在加载下一页并尝试使用自动输入的另一个连接字符串时失败。这就是为什么使用GUI界面有时会引起问题。

可能远程服务器不支持
namepippes
您可以使用实际的sqlserver db名称等连接到它吗。。看一看,我不想使用命名管道。为什么它认为我在尝试?我正在尝试使用tcp进行连接。我已经检查过了,它们都已启用。因为您将其编码为查找