1
votes

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

2
have you run in the debugger to make sure it is using the right connection string and that this is the connection that is failing? I had a left over connection string in machine.config once that did this to me.Geoff

2 Answers

1
votes

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.

0
votes

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.