开发者

WCF Service Not Connecting to SQL Database

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=T开发者_高级运维rue;
User ID=username;Password=userpass

WCF Service Not Connecting to SQL Database


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜