Friday, February 24, 2012

ADO.NET cannot connect to SQL2k, but Query Analyzer does

I have an ADO.NET (.NET 2.0) application that throws a connection exception when trying to connect to a SQL 2000 Standard server (despite what the message says about 2k5, which I assume is generic):

System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.Connect(Boolean& useFailoverPartner, Boolean& failoverDemandDone, String host, String failoverPartner, String protocol, SqlInternalConnectionTds connHandler, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject, Boolean aliasLookup)
at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(SqlConnection owningObject, SqlConnectionString connectionOptions, String newPassword, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, String newPassword, SqlConnection owningObject, Boolean redirectedUserInstance)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)

The strange thing is that I can connect just fine to this server (and run the stored procedure in question) using Query Analyzer from the client machine. I have double- and tripple-checked the credentials (and had someone else look too) and they are correct. I also checked telnet to port 1433 and it doesn't fail to connect. Ping is shut down at the firewall.

The connection string looks like this (basically):

Data Source=10.0.0.137;Initial Catalog=XXXXXX;uid=xxxxx;pwd=xxxxx

This is conecting to a remote instance across a couple firewalls. Both machines are Windows Server 2003. I don't have much more information about the SQL 2000 server machine, but the client machine is running plain vanilla server 2k3 with no third party software firewalls or a/v.

Has anyone run into this before? I know Query Analyzer and ADO.NET user different connection methods, but the permissions shouldn't be any different, right?

Thanks in advance.

--
Jeremy Wadsack
Seven Simple Machines
http://7simplemachines.com/This seems to have resolved itself. Here's my speculation on what happened.

Note that the original error message explicitly states a named-pipe connection. (Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) This requires that the firewall allow both TCP port 1433 and UDP port 1434. However, I believe our firewalls were only set to allow the TCP port. It's odd that the ADO.NET 2.0 provider seems to default to named pipes when the connection string is an IP number. I have no idea what changed (we did rebuild it, but with no updates to the connection details) and I am guessing that it's now using IP connection.

Sorry I can't provide a better resolution for anyone else who may run into this.

--
Jeremy Wadsack
Seven Simple Machines
http://7simplemachines.com/|||unluckily, this has also been plaguing me. i'm just using sql server developer edition with allowed remote connections

No comments:

Post a Comment