Saturday, February 25, 2012

Connection Error from ASP.Net under IIS: provider: Named Pipes Provider, error: 40

We experience the 40 error when our Asp.net code runs under IIS and uses named pipes to a sql server 2005 named instance.

We've tried all suggestions found on blogs and KB articles such as making sure the named pipes protocol is enabled, making sure the Browser service is started, making sure Allow Remote Connections is enabled, making sure we're not using Asp.Net 2.0 membership providers, and the list goes on and on.

We boiled it down to a simple test scenario. We open a SqlConnection to the sql 2005 box in the code with the intention of binding a datareader to a gridview, but it never gets that far because the connection.Open() fails.

If we run this test application as a virtual directory in IIS and Asp.Net 2.0, the connection.Open() fails.

If we run this test application from Visual Studio .Net using Cassini (PWS), the connection.Open() succeeds and binds to the gridview.

What could be causing the connection to fail under IIS but succeed under Cassini? We've tried setting IIS to run as a domain user and with digest authentication enabled. That made no difference.

Any help or insight is appreciated!

Could you try to answer the following questions though some of them may be already implied by your post?

(1) Is this remote connection or local connection?

(2) Is the account that runing your visual studio.net the the same as your IIS. Do you impersonate client connection in IIS?

(3) Can you make direct connection to your backend sqlserver from your virtual studio or sql server management studio?

(4) Can you try connecting using TCP instead? If not, what is the error code?

|||

(1) Is this remote connection or local connection?

-Remote connection

(2) Is the account that runing your visual studio.net the the same as your IIS. Do you impersonate client connection in IIS?

-Same account, windows authentication. No impersonation

(3) Can you make direct connection to your backend sqlserver from your virtual studio or sql server management studio?

-Management Studio works, Cassini works.. IIS does not

(4) Can you try connecting using TCP instead? If not, what is the error code?

TCP gives "server actively refused connection" error

|||

Does your connection string like "servername\instancename" or something else?

The TCP failure indicates either the server TCP listener is not up or client uses different TCP port to connect. So please check whether the TCP is enabled or not. Restart the server after the configuration change. Then check if the connection string has instancename specified. Once you find out which port the server is listening on, you can also use "tcpTongue Tiedervername,port" to connection to the server.

No comments:

Post a Comment