在.NET中连接到SQL Server时,指定的网络名称不再可用

时间:2016-06-29 13:41:22

标签: c# sql-server visual-studio-2015

我重新安装了我的主要工作电脑,但5个月后没有重新安装视觉工作室。现在我做了并开始了我的旧项目,现在它没有运行。

连接到SQL Server时出现超时错误,所以我增加了连接字符串中的超时,现在我收到了错误:

[Win32Exception (0x80004005): The specified network name is no longer available]

[SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - The specified network name is no longer available.)]
   System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +1004
   System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +798
   System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +38
   System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +722
   System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +85
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +449
   System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +108
   System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +935
   System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +143
   System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +17
   System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +139
   System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +367
   System.Data.SqlClient.SqlConnection.Open() +130
   RRHHComprobantePago.comprobante_pago.Page_Load(Object sender, EventArgs e) in c:\Users\fleon\Documents\Visual Studio 2015\WebSites\RRHHComprobantePago\comprobante_pago.aspx.cs:47
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +85
   System.Web.UI.Control.OnLoad(EventArgs e) +79
   System.Web.UI.Control.LoadRecursive() +130
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2832

在其他搜索中,我看到有人说要重新启动visual studio并重新编译。我做了,甚至重新启动,同样的错误。

我可以使用Management Studio连接到数据库并运行查询,因此我认为问题不在于数据库服务器本身。也许某种防火墙?

作为参考,只在执行sqlConn.Open()时出现错误,因此没有运行查询。另外,这是我的连接字符串:

<add name="adamConnectionString" providerName="System.Data.SqlClient" connectionString="Initial Catalog=adam;Data Source=192.168.xxx.xxx;uid=user;pwd=password;Integrated Security=false;Connection Timeout=3000000"/>

2 个答案:

答案 0 :(得分:0)

这是由于网络连接间歇性丢失。 找不到网络名称错误。

答案 1 :(得分:0)

在我看来,98% 的肯定,因为我最近有同样的经历,这是服务器提供商的网络问题。

例如:如果您从 Ionos 租用服务器,默认情况下所有远程连接都会被阻止,即使您禁用了服务器中的防火墙。您仍然无法远程连接。但是,您可以毫无问题地在服务器上进行工作。

要远程连接,您必须联系服务器提供商。他们将解释如何从您的控制面板启用防火墙端口。

我联系了我的服务器提供商,因为我几乎感到沮丧。这是他们的回应。

enter image description here

而且,哇!!每个允许的客户端都可以远程连接到服务器。

祝你成功。