WCF does not connect to Sqlserver when published on IIS

Asked

Viewed 78 times

0

I am using WCF + Sqlserver, when running by Visual Studio works perfectly, when I publish and update on 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. (Preview: Named Pipes Provider, error: 40 - Could not open a Connection to SQL Server)"

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

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

but none worked, follows the complete error:

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. (Preview: 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
Inteligentialwcf.Sistemasat6wcf.Iservice1.Recovered(String instruction) +0
Inteligentialwcf.Sistemasat6wcf.Service1client.Recovered(String instrucao) in c:... Inteligenciawcf.WCF.receber WCF(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 includedStagesBeforeAsyncPoint, Boolean includedStagesAfterAsyncPoint) +3562

  • How are you connecting ? ADO, EF,... ? Put the code of your connection but first make sure that the data of your connectionstring is being pointed out correctly.

  • Sqlconnection Connection = new Sqlconnection("Data Source=XXXXXXXX,1433; Database=XXXX; User ID=XXXXX; Password=XXXXX; ");

  • Have you tried to remove the port ? By default SQL SERVER always uses port 1433 to connect. By error it has not located where your SQL server is. Didn’t even log in.

  • I have tried this too, but I believe that this is not because connectionstring works from Visual Studio

2 answers

1


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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.