views:

620

answers:

4

Could not connect to SQL server while using web service. I get the following error:

System.Web.Services.Protocols.SoapException: Server was unable to process request. 
---> 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, Boolean ignoreSniOpenTimeout, Int64 timerExpire, SqlConnection owningObject)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(String host, String newPassword, Boolean redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, Int64 timerStart)
   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 Service.balance(String acntno) in c:\Inetpub\wwwroot\projnew_nithya\webservice\App_Code\Service.cs:line 30
   --- End of inner exception stack trace ---
+2  A: 

The error message really already tells you what it (most likely) is:

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) at

Is your SQL Server where you're trying to connect to configured to allow remote connections (from your server where the web service is running) ??

If not -> do that! That should help.

Marc

marc_s
+1 I really don't know what else I would say.
Kevin
+1  A: 

It looks like your web server is not on the same machine as your SQL server.

You need to configure you SQL Server to accept remote connections.

This is done using the "Surface Area Configuration Tool" in SQL Server

Shiraz Bhaiji
A: 

Hi,

You may get this error message even if you haven't activated mixed authentication in SQL Server (i.e., both SQL and Windows Authentication). I have experienced this once.

Prabhu
A: 

Assuming that you are using a SQL server where you can access the SQL Server Surface Area Configuration tool, please take the following steps

Open the SQL Server Surface Area Configuration Tool In that open Surface Area Configuration for Services and Connections On the left pane Click Remote Connections under Database Engine Select the radio button Local and Remote connections. Click the Apply Button. It will pop up a message that this will be enabled when the database instance is restarted.

Restarting the instance should solve your problem.

If you are using an instance where you cannot change these settings, please contact your administrator.

Above should solve the problem.

If still it is inaccessible, check the firewall to allow SQL Server instance and the SQL Browser to make connections.

regards...

Kalpak L

Kalpak