Visual Studio - Why Am I Getting - Cannot Connect To Server - A Network-Related or Instance-Specific Error - Stack Overflow

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"?

- Stack Overflow

Why am I getting “Cannot Connect to Server - A network-related or


instance-specific error”?
Asked 6 years, 11 months ago Active 8 days ago Viewed 1.5m times

I get the following error when trying to connect to SQL Server:

382 Cannot connect to 108.163.224.173.

A network-related or instance-specific error occurred while establishing a connection to SQL


Server.

111 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)
(Microsoft SQL Server, Error: 1326)

This error is thrown when I try to configure my database to gridview in Visual Studio 2010. I'm at a
loss as to how to debug this error.

How would you debug this error? What steps should I take in order to determine what is really
going on here, in addition to the one mentioned in the error message?

sql-server visual-studio database-connection azure-virtual-machine

edited Jun 20 at 9:12 asked Aug 5 '13 at 14:25


Community ♦ Sasa Shree
1 1 4,015 3 10 3

11 A ping is unreliable for testing SQL Server connectivity, ICMP echo request are disabled by default in
Windows Server. An invalid username or password is not what the error is telling you at all, that's a
completely different error. – Sean Airey Aug 5 '13 at 14:32

1 Try this article, it goes through pretty much all the steps you will need to troubleshoot your connectivity
problems: social.technet.microsoft.com/wiki/contents/articles/… – Sean Airey Aug 5 '13 at 14:33

3 See my answer here with my screen shot if you received this error with SQL Server {version} Express,
when setting it up for the first time. I came back to StackOverflow and used my answer again because it
was the only one that worked. stackoverflow.com/questions/1391503/… – MacGyver Jan 21 '14 at 3:47

I had this Issue on my virtual Server when I wanted to connect to the localhost. It appeared there was
some kind of error when launching the OS - in my case everything was solved fortunately with a clean
reboot. – Qohelet Feb 13 '15 at 7:33

Today I spent a lot of time on this, finally what worked for me is: Open Sql Server Configuration Manager
--> Protocols for <INSTANCE> --> TCP/IP --> IP Addresses(Tab). Go to last entry IP All and mention
TCP Port 1433. Now restart SQL Server (INSTANCE) using services.msc. After this, the problem got
resolved. – ani627 Feb 24 '15 at 13:20

38 Answers Active Oldest Votes

1 using
By 2 our
Next
site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 1/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

I found the following techniques helpful:

301
1. Make sure your database engine is configured to accept remote connections:
Start > All Programs > SQL Server 2005 > Configuration Tools > SQL Server
Surface Area Configuration
Click on Surface Area Configuration for Services and Connections
Select the instance that is having a problem > Database Engine > Remote
Connections
Enable local and remote connections
Restart instance

2. You may need to create an exception on the firewall for the SQL Server instance and
port you are using:
Start > Run > Firewall.cpl
Click on exceptions tab
Add sqlservr.exe (typically located in C:\Program Files (x86)\Microsoft SQL
Server\MSSQL.x\MSSQL\Bin , check your installs for the actual folder path) and port
(default is 1433 )
Check your connection string as well

From FIX : ERROR : Could not open a connection to SQL Server:

3. Check if your SQL server services is up and running properly:

Go to All Programs > Microsoft SQL Server 2008 > Configuration Tools > SQL
Server Configuration Manager > SQL Server Services
Check to make sure SQL Server service status is Running.
In addition, ensure that your remote server is in the same network. Run sqlcmd -L to
ascertain if your server is included in your network list.

4. Enable TCP/IP in SQL Server Configuration

When two or more SQL Servers are connected across network they do all
communication using TCP/IP. The default port of SQL Server installation is 1433. This
port can be changed through SQL Server Configuration Manager. TCP/IP should be
enabled for SQL Server to be connected.

Go to All Programs >> Microsoft SQL Server 2008 >> Configuration Tools >> SQL
Server Configuration Manager >> Select TCP/IP
Right Click on TCP/IP >> Click on Enable
You must restart SQL Server Services for all the changes to take effect. Right click and
go to menu properties to select location where default port of SQL Server can be
changed.

edited Jun 10 '17 at 19:41 answered Aug 5 '13 at 14:33


Teo Chuen Wei Bryan
7,572 13 41 74

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms
10of Enable
ServiceTCP/IP
. in SQL Server Configuration was the solution for me when using SQL Server 2014
E Mik Ri h d O t 21 '14 t 15 32
https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 2/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow
Express. – Mike Richards Oct 21 '14 at 15:32

74 Today I spent a lot of time on this, finally what worked for me is: Open Sql Server Configuration Manager
--> Protocols for <INSTANCE> --> TCP/IP --> IP Addresses(Tab). Go to the last entry IP All and mention
TCP Port 1433. Now restart SQL Server (<INSTANCE>) using services.msc. After this, the problem got
resolved! – ani627 Feb 24 '15 at 13:26

1 I was also facing the particular problem on my local Sql server and solved by checking the local services of
operating system and Searched for the specific Sql services and start them one by one. It worked perfect.
– Faisal Naseer Mar 10 '15 at 6:28

4 I too had the same problem, logged on to sql server found that mssqlserer service was stopped, started it.
Was able to connect to the instance now – Rak Apr 4 '15 at 9:00

15 Also REMEMBER to ENABLE SQL Server Browser service. Have setup a number of SQL servers in my
time... Yet this step always seems to have different scenarios involved :) – mschr Oct 14 '16 at 8:49

I got Solution for me :

126 Open "SQL Server Configuration Manager"

Now Click on "SQL Server Network Configuration" and Click on "Protocols for Name"

Right Click on "TCP/IP" (make sure it is Enabled) Click on Properties


2
Now Select "IP Addresses" Tab -and- Go to the last entry "IP All"

Enter "TCP Port" 1433.

Now Restart "SQL Server .Name." using "services.msc" (winKey + r)

It Will Work...

answered Sep 8 '15 at 12:34 community wiki


Irshad Khan

Trying this, yet for some reason when I right click and choose "Properties" on "TCP/IP" in windows10, it
doesn't pull up the dialog window for that. The other nodes in general in the treeview do pop up dialogs just
fine. Anyone have this issue and ideas for getting through it? – Ryan Betker - healthNCode Mar 28 '16 at
14:39

3 In SQL Server 2014 use (localdb)\mssqllocaldb instead of (localdb)\v11.0 – Shalva Avanashvili May 26 '16
at 4:48

69 Copy pasted my comment (which was posted on 24th Feb 2015 - 7 months before your post) as an answer
without giving me credits! :P – ani627 Jul 28 '16 at 15:59

2 This worked. I was not able to connect to SQL Server 2016. Made these changes and it worked ! Thanks.
– Ankur Aug 27 '17 at 16:43

1 it works for me. just had to start the services in "service.msc" after enabling TCP/IP and Named Pipes in
configuration manager. – Alif Noushad Dec 12 '17 at 5:44

Adding my heavily upvoted comment as an answer with screenshots.

I spent a lot of time on this, finally what worked for me is:


102
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
1) Open Sql Server Configuration Manager --> SQL Server Network configuration -->
our Terms of Service.for <(INSTANCE)> --> TCP/IP (double click on it).
Protocols
https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 3/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

2) Select --> IP Addresses(Tab).

3) Go to the last entry IP All and mention TCP Port 1433.

4) Press Win+R and enter services.msc.

5) Now restart SQL Server <(INSTANCE)>.

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 4/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

After this, the problem got resolved!

edited May 23 '17 at 12:18 answered Jul 28 '16 at 15:46


Community ♦ ani627
1 1 4,510 8 31 40

Cannot connect to Remote SQL server – ani627 Mar 21 '17 at 7:35

Worked for me, SQL Express 2012 – lost_in_magento Apr 1 '18 at 8:26

Worked for me in sql server 2012 after enable TCP, Added Port number 1433 to TCP ALL, and restart the
service! – Chirag Khatsuriya Mar 8 '19 at 2:03

For me additionally I had to allow TCP 1433 and UDP 1434 in the Firewall – MarkusEgle Jul 2 '19 at 12:07

I am solving that problem by opening Services then start running Sql Server (Sqlexpress)
service.
84

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 5/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

answered Feb 16 '16 at 20:14


Anik Saha
3,343 1 18 30

3 I have seen where SQL Server windows service was set to Manual Startup Type, so it did not restart on a
reboot. It should be set to Automatic. – robertburke Oct 7 '16 at 16:22

2 This is exactly what i did, My Status was Running and StartupType was Automatic , but still i faced the
issue , so i used services from Run window type services.msc then i right clicked SQL Server (SQL
EXPRESS) for context menu and just Stop and Start the service again and works fine for me, hope
helps. – shaijut Oct 25 '16 at 7:40

This Error mainly came when the SQL Service is stopped.You need to Restart the service.To go
to this window you have to search the Services like this-
22

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 6/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

Then Search for SQLSERVER(MSSQLSERVER) and Restart the service.

Hope this will work.

answered Nov 8 '17 at 16:19


Debendra Dash
3,372 25 28
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 7/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

Press window + R (Run window Open) and in run window type "services.msc" and new services
open find SQL SERVER with instance name in my case it's SQL SERVER(SQLEXPRESS) then start this
18 service and try again it works for me Hope Its Works for You also.

edited Aug 21 '19 at 7:34 answered Apr 2 '16 at 8:25


Muhammad Asad
1,391 10 20

The answer was provided previously. Dont get any reason post it again – Anik Saha Apr 11 '16 at 7:39

8 buddy am facing same problem but i do not know hot open services window then i found a way and i
thought share with people – Muhammad Asad Apr 11 '16 at 11:28

@AdnanAhmad you are welcome. Thanks for appreciation. – Muhammad Asad Jan 30 at 8:15

In case you might be using the Express Edition:

Add "\SQLEXPRESS" after your server name


17
e.g. "MY-SERVER\SQLEXPRESS"

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 8/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

edited May 28 '19 at 13:16 answered Sep 26 '16 at 13:08


Abdulrahman Bres
1,405 12 31

I had the same error when I wanted to run my WinForms project (that includes working with a
SQL Server database and that worked perfectly on my PC) on another PC. The problem was in
13 Windows Firewall on my PC. I solved this by adding two rules. This is the whole procedure how to
allow SQL Server through Windows Firewall:

1. Open "Run" and enter services.msc

2. Find the service for SQL Server (instance name) and SQL Server Browser. One at a time,
right click, select "Properties", copy the path to exe file
3. Then open firewall.cpl , click allow an application or add rule, add the previously copied
path (there is a procedure you need to follow), check Domain and Private, uncheck Public.

This is the YouTube link where you can see this procedure: Allow SQL Server through Windows
Firewall
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
edited Feb 27 '16 at 16:17 answered Feb 27 '16 at 16:10
our Terms of Service.

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 9/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

Tunaki NutCracker
107k 27 252 344 7,790 2 30 54

Works perfectly for me. Important: Add browser and server in the firewall! +1 – BendEg Mar 9 '16 at 12:24

I was having a hard time locating the sqlservr.exe file, this did the trick in locating it. – Stan May 24 '17 at
19:45

If none of the above solutions work (nothing worked for me) then just RESTART your computer
and you will be able to connect to your sql server (localhost).
11
edited Oct 9 '15 at 15:03 answered Oct 8 '15 at 10:06
Eugen Sunic
7,654 6 40 58

The reason why this will work, it´s because you just installed Sql Server and has not restarted the computer
as the installation told you to. So, do it and then the services will be created and all the necessary
configuration that is missing. – Sterling Diaz Apr 30 '16 at 1:00

After doing everything mentioned here:


http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-
10 40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error/ Still did not work for me.

Steps worked for me:

Start > Run > cmd > sqlcmd -L

It will prompt you the server name. Make sure this server name is same as the one you are trying
to get connected to in CONNECT TO SERVER box of SQL management studio.

I made this silly mistake I keep using MSSQLSERVER rather using this server name.

Hope this helps for the people who make silly mistake like me.

Thanks.

answered Feb 27 '16 at 17:47


Denn
427 5 11

You can test the following methods.

8 a
1. Check the connection string of the project.
b
1. Go to services and restart SQLServer Instance.
c
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
1. Open 'SQLServer Configuration Manager'
our Terms of Service.

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 10/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

2. In the left panel select 'SQLServer Network Configuration' and expanding it


3. Select 'Protocols for MSSQLServer'
4. In the right panel dbl click on 'TCP/IP'
5. In the 'Protocol' tab set the 'Enabled' to 'Yes'
6. In the 'IP Addresses' tab scroll to down
7. In the 'IPAll' set 'TCP Port' to 1433
d
1. Open 'Firewall with advanced security'
2. In the right tab select 'Inbound Rules'

In the middle tab find the record that 'local Port' is 1433, If you can't found it try to created it with
following levels

In the Start menu, click Run, type 'WF.msc', and then click OK
In the left panel click the 'Windows Firewall with Advanced Security'
In the right panel right-click 'Inbound Rules', and then click 'New Rule'
In the Rule Type dialog box, select 'Port', and then click Next
In the Protocol and Ports dialog box, select 'TCP', and select 'Specific Local Ports', and then
type the port number 1433, Click Next
In the Action dialog box, select Allow the connection, and then click Next
In the 'Profile' dialog box, checking the Domain, Private and Public, Then click Next
In the 'Name' dialog box, type 'SQL 1433 Port' and for a description write description for own.
Then click Finish

3. Then in the middle tab double click the found item(Instance) or created item of 'SQL
1433 Port' name by you.
4. Select 'Scope' tab in opened dialog box(SQL Server Properties)
5. In the Local PC Go to google.com in your Browser and search 'My IP'.
6. then copy of your 'IP'
7. Go to the remote server and in the 'SQL Server Properties' dialog box of 'Scope' tab, in
the 'Remote IP Address' select the 'These IP Addresses' option and click 'Add' button
8. In the opened dialog box(IP Address) select 'This IP Address or Subnet' option and
paste your 'IP', click OK button.

answered Mar 30 '17 at 7:15


MohammadSoori
1,070 10 11

This solution solves both issues network error and the service behind SQL server

I answered a similar question here, you need to stat the other open Run type-> services.msc -
8 under services -> sort by stopped you will see a bunch of stopped SQL services Right click and
start

By usingTo
ourbegin - there
site, you are 4 issues
acknowledge thathave
that you could beand
read causing the common
understand our CookieLocalDb SqlExpress
Policy, Privacy Sql
Policy, and
Server
our Terms connectivity
of Service. errors SQL Network Interfaces, error: 50 - Local Database Runtime error

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 11/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

occurred , before you begin you need to rename the v11 or v12 to (localdb)\mssqllocaldb

Troubleshooting Steps

1. You do not have the services running run this cmd, net start MSSQLSERVER or net start
MSSQL$ instancename

2. You do not have the firewall ports here configured

3. Your install has and issue/corrupt (the steps below help give you a nice clean start)
4. You did not rename the V11 or 12 to mssqllocaldb/SqlServer

I found that the simplest is to do the below - I have attached the pics and steps for help.

Resolution Steps:

First verify which instance you have installed, you can do this by checking the registry and by
running cmd

1. cmd> Sqllocaldb.exe i

2. cmd> Sqllocaldb.exe s "whicheverVersionYouWantFromListBefore" if this step fails, you can


delete with option d cmd> Sqllocaldb.exe d "someDb"
3. cmd> Sqllocaldb.exe c "createSomeNewDbIfyouWantDb"

4. cmd> Sqllocaldb.exe start "createSomeNewDbIfyouWantDb"

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 12/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

edited Jun 14 at 17:26 answered Mar 1 '17 at 5:17


transformer
1,624 14 32

I am using SQL Server 2016 and Window 10.

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 13/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

First thing is to allow remote connection to SQL Server. What I did is to type
sqlservermanager13.msc at start menu in order to open the SQL Server Configuration
Manager. Make sure the TCP/IP status is enabled.

Check your TCP port number by double click TCP/IP protocol name. Usually it is 1433 by default.

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
The following procedures configure the Windows Firewall by using the Windows Firewall with
our Terms of Service.
Advanced Security Microsoft Management Console (MMC) snap-in. The Windows Firewall with
https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 14/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

Advanced Security only configures the current profile.

To open a port in the Windows firewall for TCP access

1. On the Start menu, click Run, type WF.msc, and then click OK.
2. In the Windows Firewall with Advanced Security, in the left pane, right-click Inbound
Rules, and then click New Rule in the action pane.
3. In the Rule Type dialog box, select Port, and then click Next.
4. In the Protocol and Ports dialog box, select TCP. Select Specific local ports, and then
type the port number of the instance of the Database Engine, such as 1433 for the
default instance. Click Next.
5. In the Action dialog box, select Allow the connection, and then click Next.
6. In the Profile dialog box, select any profiles that describe the computer connection
environment when you want to connect to the Database Engine, and then click Next.
7. In the Name dialog box, type a name and description for this rule, and then click Finish.

Another thing to configure.

To open access to SQL Server when using dynamic ports

1. On the Start menu, click Run, type WF.msc, and then click OK.
2. In the Windows Firewall with Advanced Security, in the left pane, right-click Inbound
Rules, and then click New Rule in the action pane.
3. In the Rule Type dialog box, select Program, and then click Next.
4. In the Program dialog box, select This program path. Click Browse, and navigate to the
instance of SQL Server that you want to access through the firewall, and then click
Open. By default, SQL Server is at C:\Program Files\Microsoft SQL
Server\MSSQL13.MSSQLSERVER\MSSQL\Binn\Sqlservr.exe. Click Next.
5. In the Action dialog box, select Allow the connection, and then click Next.
6. In the Profile dialog box, select any profiles that describe the computer connection
environment when you want to connect to the Database Engine, and then click Next.
7. In the Name dialog box, type a name and description for this rule, and then click Finish.

Have a look at Microsoft doucmentation Configure a Windows Firewall for Database Engine
Access

answered Nov 11 '16 at 7:06


Fred
621 6 12

On my PC Windows 10 the sql server instance is at C:\Program Files\Microsoft SQL


Server\MSSQL13.SQLEXPRESS\MSSQL\Binn\Sqlservr.exe – Mayer Spitzer Apr 24 '19 at 2:46

I was experiencing the same problem and the problem was that I hade several projects in the
solution ( Web and Droid ) and even though Default project was choosen in the Package Manager
5 Console it used the connection string from the Droid project:

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 15/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

PM> update-database -Verbose


Using StartUp project 'Droid'. <-- DROID
Using NuGet project 'Web'. <-- WEB
Specify the '-Verbose' flag to view the SQL statements being applied to the target
database.
<!-- BAD TARGET DATABASE -->
Target database is: 'DefaultConnection' (DataSource: .\SQLEXPRESS, Provider:
System.Data.SqlClient, Origin: Convention).
System.Data.SqlClient.SqlException (0x80131904): 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: SQL Network Interfaces, error: 26 -
Error Locating Server/Instance Specified)
[REMOVED TEXT]
ClientConnectionId:00000000-0000-0000-0000-000000000000
Error Number:-1,State:0,Class:20
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

After setting the Startup Project to Web and the Default Project in Package Manger Console I got
it to work.

answered Oct 15 '16 at 18:22


Westerlund.io
2,081 4 21 34

I have to run SQL Server Browser service into SQL Server Configuration Manager. Installation
can't discover newly created service without this.
5
edited Nov 12 '16 at 9:18 answered Jan 27 '16 at 11:11
MarkosyanArtur
955 9 9

1 Im not there yet but i'm getting closer. In Visual studio after doing this also disconnect and reconnect,
getting the same error still but now at least from behind VS2015 i can no create tables, and databases i
create seam to run now. (ea ,no dark cross icon over them) – user3800527 Oct 13 '16 at 12:28

1 note after your command, this resulted in server name on a local machine Start > Run > cmd > sqlcmd -L –
user3800527 Oct 13 '16 at 12:45

While the above solutions should work in 90% of the cases, but if you are still reading this
answer!!! You are probably trying to connect to a different server than intended. It may be due to
4 a configuration file pointing to a different SQL server than the actual server you think you are
trying to connecting to.

Happened to me atleast.

answered Apr 28 '16 at 7:51


Arjmand
313 2 9

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
1 Happened to me as well. Should have checked that before checking trying to diagnose the firewall. I had
our Terms of the
Service
right .connection string, but I was running the the wrong project in the solution... – VSO Aug 8 '16 at

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 16/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow
14:22

I moved from a work laptop on Windows 7 to a work laptop on Windows 10. I had been
successfully using SSMS2016 on Windows 7.
4 The same issue applied using SSMS2012 or SSMS2016. My access to the 10 sql servers using
windows authentication was still the same. I could test this from another server. However, 2 of
the 10 servers would not connect from my laptop. Both were ms sql server 9 but I could
connect to other sql server 9 databases.

The solution was to add a firewall rule (using Windows Firewall with Advanced Security).

Create an Incoming rule for each SSMS eg C:\Program Files (x86)\Microsoft SQL
Server\130\Tools\Binn\ManagementStudio\Ssms.exe

I'm not a network expert so I've not included the details but hopefully it will point you in the right
direction.

Error msg (pre firewall rule) "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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (.Net
SqlClient Data Provider)"

edited Jan 31 '17 at 21:27 answered Jan 17 '17 at 9:55


JohnC
666 6 18

Why this error is so boresome and noisy, just because it can occur in varied situation.

I have done all approchs above here, and still being sucked. So make sure u have done the
4 same as me before browsing downward.

Maybe I am not able to fix ur situation instantly, but I can point out a direction or thinking to
u(The one who finally slide down here). I have started to ponder the error of my running program
occurring after I made sure that the instance name is clearly right and set my database to allow
remote control following the methods above. After then, I suspected something wrong
happening in my code snippet of SQL connection.

Solution of my problem:

Check my sqlconnection function

Click to see its configuration

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 17/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

New a connection

Select ur server name

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 18/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

It works for me with pondering what exactly happen in the process of connection.Hope my
thinking will lead u to kill ur error.

edited Jun 20 at 9:12 answered Nov 14 '17 at 10:57


Community ♦ Chase07
1 1 411 3 9

By using our This


site, helped
you acknowledge
me find thatthat you have
I needed read andthe
to REMOVE understand ourfor
port number Cookie Policyconnection
a LocalDB , Privacy Policy, and
string, when
our Terms of using
ServiceEntity
. Framework. – ryanwebjackson Jun 26 '18 at 21:37

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 19/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

I tried all the other answers on this question and some if not all probably played a part in getting
this working for me, but I still couldn't connect to the DB remotely. I was using a SQL Server on
4 an Azure VM.

I eventually remembered that the VM has endpoints that are controlled by the Azure account
proxy, so I went on to the Azure Portal and added 1433 as an available endpoint and I could
connect to my SQL instance.

Hope this helps someone who has tried all the other answers and is still having no luck!

edited Jun 25 '18 at 11:03 answered May 26 '16 at 14:52


John
1,116 13 22

Summary

To fix this issue encountered while running local app vs remote database, use SQL Server
4 Configuration Manager to add an alias for the remote database.

Details

I had run into this problem recently when transitioning from a Windows 7 to a Windows 10 laptop.
I was running a local development and runtime environment accessing our Dev database on a
remote server. We access the Dev database through a server alias setup through SQL Server
Client Network Utility (cliconfg.exe). After confirming that the alias was correctly setup in both the
64 and 32 bit versions of the utility and that the database server was accessible from the new
laptop via SSMS, I still got the error seen by the OP (not the OP's IP address, of course).

It was necessary to use SQL Server Configuration Manager to add an alias for the remote Dev
database server. Fixed things right up.

edited Jun 26 '18 at 14:27 answered Nov 2 '17 at 14:00


Bill Needels
352 3 9

You may check service status of MS SQL Server 2014. In Windows 7 you can do that by:
By using our
1. site,
Go to yousearch
acknowledge that "SQL
and Type you have read 2014
Server and understand our Cookie
Configuration Policy, Privacy Policy, and
Manager
4
our Terms of Service.
2. Then click on "SQL Server Service" on left menu
https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 20/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

3. Check the instance of SQL Server service status if it is stopped or running


4. If it has stopped, please change the status to running and log in to SQL Server Management
Studio 2014

edited Dec 5 '18 at 14:42 answered Jul 16 '17 at 7:36


Can Chamara
72 10 149 1 2

My issue started when I tried to change the server from IIS Express to Local IIS (while using
LocalDB).
3

I was using LocalDB (for dev purposes), and when I went to revert from Local IIS to IIS Express,
Visual Studio had switched my data source from Data Source=(LocalDb)\MSSQLLocalDB to
Data Source=.\SQLEXPRESS

Incorrect connection string

<add name="DefaultConnection" connectionString="Data


Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SurveyTestsDB.mdf;Initial
Catalog=SurveyTestsDB;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />

Correct connection string

<add name="DefaultConnection" connectionString="Data Source=


(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\SurveyTestsDB.mdf;Initial
Catalog=SurveyTestsDB;Integrated Security=True" providerName="System.Data.SqlClient" />

Hope this helps someone out there.

answered Feb 20 '17 at 22:29


megamaiku
375 2 10

Also do not make the silly mistake of using / instead of \ in the connection string. – andrew pate Mar 9 '17
at 14:42

Along with trying everything as suggested by Teo Chuen Wei Bryan, make sure you are also
referring to the correct Server/Instance name in the connection string.
3 If you are using the short form of host name/Instance on the database server or in the web.config
file, make sure you use the fully qualified domain name(FQDN)/Instance
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service
Also, to test. connectivity from a server where SQL server client is NOT present,
https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 21/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

--> create a text file and change its file extension to .udl

--> Right click the file and you can see connection tab.

--> Input server name and log on information to test connection to the database server.

Hope this helps.

answered Mar 15 '17 at 21:35


SanthoshM
421 4 5

If you suddenly encounter this error say in a production environment and nothing has changed,
try the following 4 items in the order below to see if it gets fixed.
3 1. restart the sql server service.
2. restart the service (say IIS) that is calling into sql server. (the problem is probably here if the
time between the start of the service call to SQL server and the time you end up getting the
response error is super short (about one or two second).
3. restart the server sql server is on.
4. restart the server the calling service is on.

answered Apr 24 '17 at 3:33


Barka
7,920 12 55 86

When I experienced this error in Visual Studio,

3 “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)”

...it was during the execution of the following C# code, which was attempting to obtain my SQL
Server data to display it in a grid. The break occurred exactly on the line that says
connect.Open():

using (var connect = Connections.mySqlConnection)


{
const string query = "SELECT Name, Birthdate, Narrative FROM Friends";
using (var command = new SqlCommand(query, connect))
{
connect.Open();
using (var dr = command.ExecuteReader())
{
while (dr.Read())
{
// blah
}
}
}
}

By usingItour
wassite, you acknowledge
inexplicable that the
because you SQL
have read
queryand understand
was our Cookie
very simple, Policy
I had the , Privacy
right Policy, and
connection string, and
the
our Terms of database
Service. server was available. I decided to run the actual SQL query manually myself in SQL

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 22/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

Management Studio and it ran just fine and yielded several records. But one thing stood out in the
query results: there was some improperly encoded HTML text inside a varchar(max) type field
within the Friends table (specifically, some encoded comment symbols of the sort <!-- lodged
within the "Narrative" column's data). The suspect data row looked like this:

Name Birthdate Narrative


==== ========= ==============
Fred 21-Oct-79 &lt;!--HTML Comment -->Once upon a time...

Notice the encoded HTML symbol " &lt; ", which stood for a "<" character. Somehow that made
its way into the database and my C# code could not pick it up! It failed everytime right at the
connect.Open() line! After I manually edited that one row of data in the database table Friends
and put in the decoded "<" character instead, everything worked! Here's what that row should
have looked like:

Name Birthdate Narrative


==== ========= ==============
Fred 21-Oct-79 <!--HTML Comment -->Once upon a time...

I edited the one bad row I had by using this simple UPDATE statement below. But if you had
several offending rows of encoded HTML, you might need a more elaborate UPDATE statement
that uses the REPLACE function:

UPDATE Friends SET Narrative = '<!--HTML Comment -->Once upon a time...' WHERE Narrative
LIKE '&lt%'

So, the moral of the story is (at least in my case), sanitize your HTML content before storing it in
the database and you won't get this cryptic SQL Server error in the first place! (Uh, properly
sanitizing/decoding your HTML content is the subject of another discussion worthy of a separate
StackOverflow search if you need more information!)

answered May 22 '17 at 20:50


ShieldOfSalvation
858 8 18

Try adding a , and a port number (as in ,1433 ) to the end of your connection string.

edited Jun 7 '18 at 14:53 answered Jun 7 '18 at 13:44


3
Patrick Kalyan Hurkat
1,550 6 17 27 61 1

Xml tag arrangement in Web.config is important

First
3
<configSections>
<!-- For more information on Entity Framework configuration, visit
http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework"
By using our site, you acknowledge that you have read and understand our Cookie Policy
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, , Privacy Policy, and
EntityFramework,
our TermsVersion=6.0.0.0,
of Service. Culture=neutral, PublicKeyToken=b77a5c561934e089"

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 23/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow
requirePermission="false" />
</configSections>

After

<connectionStrings>
<add name="SqlConnectionString" connectionString="Data Source=.; Initial
Catalog=TestDB; Trusted_Connection=True;" providerName="System.Data.SqlClient" />
</connectionStrings>

edited Dec 5 '18 at 17:00 answered Dec 25 '17 at 8:52


Can pejman
72 10 462 3 8

In my situation MSSQLSERVER service had a problem so I restarted the service and problem
solved.
3 So I recommend to go to Services app by : Windows key, search "Services", then find your Sql
instance usually "SQL Server (MSSQLSERVER)" at for Microsoft sql server. Right click on
service and click on Start, if disabled click on Restart.

answered Jul 7 '19 at 8:15


Mohamad Reza
Shahrestani
993 2 14 23

This error occurs when your sql server instance is stopped .

GO to all Programs>SQL Server >Configuration tools>SQL SERVER CONFIGURATION


2 MANAGER

then click on SQL sERVER SERVICES, list of instances will appear, select instance in question
and click on play icon on top tool bar, hope this will help.

this answer is very late(but better late than never;)

answered Apr 16 '16 at 12:58


Alex
2,742 2 18 41

I resolved this problem by setting the project that makes use of Entity Framework as the start-up
project and then run the "update-database" command.
2
answered Oct 22 '16 at 20:34
user1796440
288 2 10

1 2 Next
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service
Highly active .question. Earn 10 reputation in order to answer this question. The reputation requirement helps

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 24/25
7/10/2020 visual studio - Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? - Stack Overflow

protect this question from spam and non-answer activity.

By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.

https://stackoverflow.com/questions/18060667/why-am-i-getting-cannot-connect-to-server-a-network-related-or-instance-speci 25/25

You might also like