WCF does not connect to SQLServer when published in IIS

0

I'm using WCF + SQLServer, when I run it through Visual Studio it works perfectly, when I publish and update in IIS an error occurs:

  

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

I have already followed several forums and tutorials for connection like:

link

link

but none worked, complete error follows:

  

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
  IntelligenceWCF.SistemasAT6WCF.IService1.RecoverData (String   instruction) +0
  IntelligenceWCF.SistemasAT6WCF.Service1Client.RecoverData (String   instruction) in c: ... WCF.WCF.receberWCF (String query)   in c: ... IntelligenceWCF.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

    
asked by anonymous 26.09.2017 / 20:26

2 answers

1

If you put the correct connection string you may be having the connection blocked by the server firewall and you will have to open the port on the firewall to access the sqlserver. Follow the tutorial below.

link

    
11.01.2018 / 15:50
0

I have the same situation, but it's working. My connection string is: Data Source = xxxxxxxx; Initial Catalog = xxxxx; User ID = xxxxx; Password = xxxxxxxxxxx

Verify that the sql server service (instance) is active on the server

    
11.01.2018 / 15:46