0

Estou utilizando WCF + SQLServer, quando executo pelo Visual Studio funciona perfeitamente, quando publico e atualizo no IIS ocorre um erro:

"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)"

já segui diversos fóruns e tutoriais para conexão como:

https://www.mssqltips.com/sqlservertip/2340/resolving-could-not-open-a-connection-to-sql-server-errors/

http://www.technologycrowds.com/2014/02/could-not-open-connection-to-sql-server.html

porém nenhum funcionou, segue o erro completo:

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]: 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)

[FaultException`1: 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)]
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +153
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +336
InteligenciaWCF.SistemasAT6WCF.IService1.RecuperarDados(String instrucao) +0
InteligenciaWCF.SistemasAT6WCF.Service1Client.RecuperarDados(String instrucao) in c:... InteligenciaWCF.WCF.receberWCF(String query) in c:... InteligenciaWCF.GCLogin.lnkAcessar_Click(Object sender, EventArgs e) in c:...
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +116
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +106
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9754102 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3562

4
  • Como você está conectando ? ADO, EF,... ? Posta o código de sua conexão mas antes certifique-se que os dados de sua connectionstring estejam sendo apontados corretamente. 26/09/2017 às 18:52
  • SqlConnection connection = new SqlConnection("Data Source=XXXXXXXX,1433; Database=XXXX; User ID=XXXXX; Password=XXXXX; ");
    – Suporte
    28/09/2017 às 17:17
  • Ja tentou tirar a porta ? Por default o SQL SERVER sempre usa a porta 1433 para se conectar. Pelo erro ele não localizou onde está seu servidor SQL. Não chegou nem no login. 28/09/2017 às 17:34
  • Ja tentei isso também, mas acredito que não seja isso por conta da connectionstring funcionar do Visual Studio
    – Suporte
    28/09/2017 às 18:17

2 Respostas 2

1

Se você colocou a string de conexão correta você pode estar tendo a conexão bloqueada pelo firewall do servidor e terá que abrir a porta no firewallpara acessar o sqlserver. Siga o tutorial abaixo.

https://docs.microsoft.com/pt-br/sql/sql-server/install/configure-the-windows-firewall-to-allow-sql-server-access

0

Tenho a mesma situação, porém está funcionando. Minha string de conexão é: Data Source=xxxxxxxx;Initial Catalog=xxxxx;User ID=xxxxx;Password=xxxxxxxxxxx

Verifique se o servico (instância) do sql server está ativa no servidor

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .