Marcos Dell' Antonio - Blog sobre .NET, Web, Padrões de projeto e outros assuntos

Segunda-feira, Abril 03, 2006

provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server

E aí, já receberam essa linda mensagem de erro? Pra quem nunca usou o SQL Server ou o Server Explorer do VS, isso é uma novidade. Perdi algumas horas pra descobrir qual era o problema, até que achei um post em um blog dizendo:

I got this error immediately after installing VS2005 & SQL Server 2005 Express and trying to establish my first connection using the new server - not a good start at all - and by the looks of it, it's happened to many hundreds, if not thousands, of others too.

Generally this error occurs if you cannot connect to the SQL server - as the message says (no sh*t). However, what's not obvious is why...

First suggestion is to make sure that you specifiy the instance name as well as the server name (christ knows why, but when MS refer to "Server Name" they really mean "Server Instance Name") eg if your server was named 'bigturnip' then you need to specify 'bigturnip\sqlexpress' (where sqlexpress is the instance name - this one just happens to be the default used by SQL Server 2005 SQLExpress).

If that doesn't help, then go into the SQL Server Configuration Manager and make sure you've enabled Named Pipes & TCP (if you're using it) and also go into the Surface Area Configuration tool and make sure you've set it for local &/or remote connection for the connection types you want to use. Then restart the SQL Server (instance) service.

HTH

Tim

Link para o post: http://geekswithblogs.net/timh/archive/2006/01/30/67586.aspx

Ou seja, em Server Name não vai somente o nome da instância, mas também o nome da máquina. Aqui o nome do host é dsv1 e da instância é sqlexpress, logo fica da seguinte forma: dsv1\sqlexpress.

3 Comments:

  • Olá Marcos
    veja o meu exemplo: estou em uma maquina que conecta em outra ( banco de dados 2000 sql server), mostra o mesmo erro.
    acho que pode ser permissao, mas o que tenho que fazer ?

    By Anonymous Anônimo, at 4:04 PM  

  • Olá "anônimo".

    Não posso te dizer exatamente o que está acontecendo pois eu não uso SQL Server. Mas você chegou a ler isso:

    If that doesn't help, then go into the SQL Server Configuration Manager and make sure you've enabled Named Pipes & TCP (if you're using it) and also go into the Surface Area Configuration tool and make sure you've set it for local &/or remote connection for the connection types you want to use. Then restart the SQL Server (instance) service.

    Valeu!

    By Blogger Marcos, at 5:25 PM  

  • For SQL 2000:
    1) Apply SP4;
    2) In SQL Server Network Utility change TCP/IP port 1433 to 1433,1533;
    3) Restart SQL service;
    4) Test your application;
    5) Change TCP/IP port to 1433.

    By Anonymous Carlos, at 2:08 PM  

Postar um comentário

<< Home