【问题标题】:Trouble connecting to SQL when publishing application to remote server将应用程序发布到远程服务器时无法连接到 SQL
【发布时间】:2016-05-20 02:31:28
【问题描述】:

应用程序已加载,但当应用程序尝试与 SQL 建立连接时,加载需要一段时间然后返回错误。使用 DataLink(.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.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity 身份、SqlConnectionString 连接选项、SqlCredential 凭证、对象 providerInfo、字符串 newPassword、SecureString newSecurePassword、布尔重定向用户实例、SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool 池,字符串 accessToken,布尔值 applyTransientFaultHandling) +1394
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions 选项,DbConnectionPoolKey poolKey,对象 poolGroupProviderInfo, DbConnectionPool 池,DbConnection owningConnection, DbConnectionOptions 用户选项)+1120
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool 池,DbConnection owningObject,DbConnectionOptions 选项, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +70
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal 旧连接)+964
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal 旧连接)+114
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean 允许创建、布尔型仅OneCheckConnection、DbConnectionOptions userOptions、DbConnectionInternal& 连接)+1631
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +117
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
1 重试,DbConnectionOptions 用户选项、DbConnectionInternal oldConnection、DbConnectionInternal& 连接)+267
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection 外部连接,DbConnectionFactory 连接工厂, 任务完成源1 retry, DbConnectionOptions userOptions) +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[] 数据表,Int32 startRecord,Int32 maxRecords,字符串 srcTable、IDbCommand 命令、CommandBehavior 行为)+177
System.Data.Common.DbDataAdapter.Fill(数据集数据集,Int32 startRecord,Int32 maxRecords,String 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__249.MoveNext() +1400 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+13847892
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+61
System.Web.Util.WithinCancellableCallbackTaskAwaiter.GetResult() +32
System.Web.UI.d__523.MoveNext() +9283

【问题讨论】:

  • 可能远程服务器不支持NamePipes你可以使用实际的sqlserver数据库名称等连接到它。看看Connection Strings Sql Server
  • 我不想使用名称管道。为什么它认为我在努力?我正在尝试使用 tcp 进行连接。我已经检查过了,它们都已启用。
  • 因为您对其进行了编码以在此行SQLConnectionString.DataSource = "10.10.xxx.xx,1433"; 中查找 ip 地址/名称管道,请阅读我在之前评论中发布的关于如何使用 Sql Server 在 C# 中配置连接字符串的链接..跨度>
  • 我查看了您发送给我的页面,根据该站点,一切看起来都是正确的。我正在使用“网络库 = DBMSSOCN”将其指定为 tcp。在那个网站上它说,“DBMSSOCN=TCP/IP 是如何使用 TCP/IP 而不是命名管道。”
  • 您是否负责管理远程服务器..?如果没有,请与 dba 联系并让他们确认 TcpIp/NamedPipes 是否支持以及是否已打开.. 听起来您将不得不更改代码.. 这并不难

标签: c# asp.net sql-server iis tcp


【解决方案1】:

我想通了,web.config 文件中有一个杂项连接字符串导致程序返回该错误。当我测试不同的连接方法时,它是由 Visual Studio 自动添加的。我删除了它并且它起作用了。我的连接字符串没有任何问题,当下一页加载并尝试使用自动输入的其他连接字符串时它失败了。这就是为什么使用 GUI 界面有时会导致问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多