-1

Got a SqlException.

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)

Trying to populate the screen with a list of Products.

The bug

It’s reading the connection string ok otherwise it would tell us. It’s configured to except remote connections.

This document claims to have an exhaustive log of troubleshooting steps. Every step we take below this link is related to it. We’re using SQL Server 2014. http://social.technet.microsoft.com/wiki/contents/articles/2102.how-to-troubleshoot-connecting-to-the-sql-server-database-engine.aspx

It didn’t help. I did everything.

  • Enabled remote connections.

  • I used ipconfig as admin in console to verify IP address and pinged all of them and my computer with the ping command.

  • They all reported ok. Tested connecting to sql server from visual studio using as example “tcp:ipv4/myInstance.” Which was read ok. Reinstalled SQL Server 2014. Nothing.

  • I reinstalled the whole OS. Didn’t work.

If you require more explicit infomation please ask me, I'll give as much detail as I can.

Community
  • 1
  • 1
Jordan Nash
  • 25
  • 10
  • Normally the instance specific SQL error points to the application not being able to find the SQL server. This is usually due to one of 2 situations, either an incorrect server address ie. 192.168.0.10 instead of 192.168.0.10\sqlexpress. The other known culprit is incorrect configuration settings. What SQL are you running? – ThatChris Nov 01 '16 at 11:16
  • I'm running the following SQL code. private const string QUERY_SELECT = "SELECT * FROM " + TABLE_NAME + " ORDER BY ProductDescription ASC "; – Jordan Nash Nov 01 '16 at 11:19
  • 1
    The query you are running will not be the problem here. The problem is before this. Could you post your connection string, without the password obviously. – ThatChris Nov 01 '16 at 11:23
  • JordanNash, read the duplicate link mentioned above, this covers most of the usual culprits – ThatChris Nov 01 '16 at 11:25
  • Also - beaware of SQL Injection... – Stuart.Sklinar Nov 01 '16 at 11:34
  • public const string CONNECTION_STRING = "Data Source=.SQLEXPRESS;Initial Catalog=DatabaseName;Integrated Security=True"; – Jordan Nash Nov 01 '16 at 11:50
  • `.SQLEXPRESS` is not a valid data source. Use `.\SQLEXPRESS` instead (you might also need another escaping backslash in some cases). It would appear your tests were not accurate as you would not be able to ping or connect to anything called `.SQLEXPRESS` – Nick.Mc Nov 01 '16 at 13:36
  • When I look at the screenshot of your bug you have yet another connection string in the debug window. You should take a look here https://www.connectionstrings.com/sql-server/ and get your connection string correct – Nick.Mc Nov 01 '16 at 13:39
  • @Nick.McDermaid All I had to do was change the connection string and add a double back slash. "Data Source=.\\SQLEXPRESS;Initial Catalog=DatabaseName;Integrated Security=True"; .It was that simple! – Jordan Nash Nov 02 '16 at 02:31

1 Answers1

0

If you are sure that the specified instance name is correct you can check the following in the Sql Server Configuration Manager:

Sql Server Configuration Manager

Firstly, check under protocols in the nodes on the left:

Protocols

And make sure that both TCP/IP and Named Pipes are enabled.

If this is disabled on any of these nodes connections to the SQL server will fail.

Also under SQL server Services, make sure the browser service is enabled.

Also, is the server and the pc you are connecting from the same pc?

ThatChris
  • 752
  • 1
  • 4
  • 18
  • Ahh I didn't enable Named pipes under your highlighted node so I enabled it. SQL Browser service was enabled. It all works now though. Also yes I was doing this all locally from my computer. – Jordan Nash Nov 02 '16 at 02:41
  • Cool, if this answer solved your issues would you be so kind as to accept this as the answer please? I am glad I could help – ThatChris Nov 02 '16 at 04:42
  • Done. Thanks! For the record I want to say that both yours and Nick.McDermaid's answer dated 2016-11-01 13:36:58Z helped me solve this. – Jordan Nash Nov 02 '16 at 06:34