views:

44

answers:

2

Problem

When making calls to a SQL database from a WCF service we receive the following error:

"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"

Our Setup

We have a WCF service hosted on an internal server behind the firewall. That service makes calls to SQL. When making calls to the WCF service from inside the firewall, the service can communicate with the SQL server fine. We moved site outside the firewall and the network guys gave me a port to use for talking between the site and the WCF service. When making calls to the service from the site outside the firewall, the service gets an error when connecting to the database. We are using SQL authentication in the connection string to connect to the database.

Connection String Example:

Data Source=SQLServer;Initial Catalog=Database;
Persist Security Info=True;
User ID=username;Password=userpass

alt text

+1  A: 

Remote over to the server and run the following command

telnet <YOUR SQL SERVER> 1433

I'm assuming here that your SQL Server is on port 1433, which is the default, but your DBA can specify another port if they so desire, so watch out... If you get a blinking cursor, the port is open and you probably need to check your conection string. If you get an error, your firewall is likely blocking you.

Dave Markle
We know the SQL port is being blocked by the firewall. We do not want to open the SQL Server port to outside the firewall. The only thing that needs to connect to the SQL server is the WCF service.
Jamie
It's proper for the SQL port to be blocked going out, of course. But are you 100% sure it's not being blocked by something going *in*? You aren't 100% sure until you check.
Dave Markle
Are you talking about opening up port 1433 at the firewall for incoming traffic? We do get an error when we telnet to port 1433 from outside the firewall, but we don't get an error when we telnet from the WCF service box. Again nothing outside of the firewall needs to connect to the SQL Server.
Jamie
No. I'm talking about running the telnet command on the box that's trying to talk to SQL server to verify that it can connect to the server's port.
Dave Markle
Yes, we can connect to port 1433 on the SQL Server from the box running the WCF Service.
Jamie
I'd say it would have to be a problem with your connection string...
Dave Markle
A: 

I don’t know exactly what fixed it. We ended up putting the service into a production environment and referencing that in the code. We worked through an issue with the HTTP binding and specified fields. We put this out there and it connected to SQL. I don't know why that fixed it, but it’s working.

Jamie