Cannot Connect to Server - A network-related or instance-specific error
Asked Answered
M

57

529

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

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)

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?

Mounts answered 5/8, 2013 at 14:25 Comment(15)
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.Notecase
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/…Notecase
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. #1392003Gotha
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.Clintonclintonia
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.Jaw
This was discussed on Meta.Arlina
I had the same problem. It turned out to be a missing connection string entry in my web config file that caused this issue.Licensee
I found this post to be very helpful. Try it.Swetlana
I've done all of the answers and all of the comments' suggestions and none of them worked. :( I'm trying to connect to a 2016 SQL server and the service is running, I've set the TCP port to 1433 for all IPs and it's still not working.Caerphilly
This could also be caused by something simple such as a server name change. I changed the name of my server but forgot to update my data source and got this error.Corwun
Also, you need to turn off windows firewall.Georgena
Related post - How do I fix the error 'Named Pipes Provider, error 40 - Could not open a connection to' SQL Server'?Sinful
I had the same error. In my case I had not spelled the name of the server correctly. Sometimes it's the simple things.Azazel
Not enough context. At the very least a connections string should have been shown.Ptolemaic
I resolved the issue I was having by adding the port number and setting TrustServerCertificate to true. The command used for this is as follows: Scaffold-DbContext 'Server=localhost;Database=Northwind;trusted_connection=True;TrustServerCertificate=True;' Microsoft.EntityFrameworkCore.SqlServerSothena
G
341

I found the following techniques helpful:

  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
  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.

Gavra answered 5/8, 2013 at 14:33 Comment(16)
Enable TCP/IP in SQL Server Configuration was the solution for me when using SQL Server 2014 Express.Castellany
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!Jaw
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.Volcanism
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 nowUnruly
Open your SQL Server Configuration Manager > then select the SQL Server Services > RIght click > StartEngenia
dead link :) .. no post in that linkUpsurge
@thanby: Glad it helped! I checked this today and found that 21 people have upvoted it! Thanks.Jaw
I'm getting this error while creating a plugin for nopCommerce. The rest of nopCommerce is working fine, connecting to the same server. I'm trying to create an Entity Framework connection to a different schema/instance on the same server. I know the connection parameters are correct, I use the same connection string in another web app which is working fine. I guess I should ask a separate question.Hip
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 :)Cudlip
@Cudlip Thanks you! After I did everything the others already have written, it still didn't work - this one solved itWilmawilmar
Also, you need to turn off windows firewall.Georgena
SQL Server Browser has to be running if you want to allow remote access to named instances. Furthermore, SQL Server Browser requires a firewall rule for UDP port 1434 to be added. See learn.microsoft.com/en-us/sql/database-engine/configure-windows/… for more info.Clarence
So just shooting random blanks hoping that one is the error? OP asked about how to DEBUG this...Doherty
Any one try on mac with msssql on docker ?Gunflint
@Jaw It doesn't works for me :(Esque
@Jaw Your a legend! God bless you, wish you the best! Oh man, I spent hours on this and no one mentioned the Port part....Masbate
J
185

Adding my heavily upvoted comment as an answer with screenshots.

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

  1. Open Sql Server Configuration Manager --> SQL Server Network configuration --> Protocols for <(INSTANCE)> --> TCP/IP (double click on it).

enter image description here

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

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

enter image description here

  1. Press Win+R and enter services.msc.

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

enter image description here

After this, the problem got resolved!

Jaw answered 28/7, 2016 at 15:46 Comment(7)
Cannot connect to Remote SQL serverJaw
Worked for me, SQL Express 2012Odonto
Worked for me in sql server 2012 after enable TCP, Added Port number 1433 to TCP ALL, and restart the service!Hearty
For me additionally I had to allow TCP 1433 and UDP 1434 in the FirewallLatanya
yes, setting port number 1433 did it, seems like by default that's just emptyDim
1) Open Sql Server Configuration Manager --> SQL Server Network configuration --> Protocols for <(INSTANCE)> --> TCP/IP (double click on it). worked for mePaleontology
Check this post to fix windows authentication mode doesn't work.Fructificative
M
179

I got Solution for me :

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

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...

Magnetochemistry answered 5/8, 2013 at 14:25 Comment(10)
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?Maskanonge
In SQL Server 2014 use (localdb)\mssqllocaldb instead of (localdb)\v11.0Variate
Copy pasted my comment (which was posted on 24th Feb 2015 - 7 months before your post) as an answer without giving me credits! :PJaw
This worked. I was not able to connect to SQL Server 2016. Made these changes and it worked ! Thanks.Polysemy
Also, you need to turn off windows firewall.Georgena
it works for me. just had to start the services in "service.msc" after enabling TCP/IP and Named Pipes in configuration manager.Brahe
I just restarted the services and it worked fine for meCrisscross
worked like magic! I'm using SQL Server 2017 btw.. but still workedEmikoemil
I spent 2 hours solving this and finally, this solution workedTowers
If someone encounter the same problem I got - SQL server error 10048, So the solution is to restart 'all' the sql server services and not only the single instance.Horrorstruck
S
104

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

service Image

Spadix answered 16/2, 2016 at 20:14 Comment(2)
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.Ingurgitate
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.Fructificative
A
31

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- enter image description here

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

enter image description here

Hope this will work.

Arrow answered 8/11, 2017 at 16:19 Comment(0)
M
22

In case you're using the Express Edition:

You need to add \SQLEXPRESS after your server name

e.g. MY-SERVER\SQLEXPRESS

enter image description here

Monkish answered 26/9, 2016 at 13:8 Comment(1)
I had a problem where I was using \\ instead of \ . For some reason, one of my applications worked, and another one didn't. even though the 2nd one was a stripped down copy of 1st one.Odle
S
17

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

Simonize answered 27/2, 2016 at 16:10 Comment(2)
Works perfectly for me. Important: Add browser and server in the firewall! +1Ornithopod
I was having a hard time locating the sqlservr.exe file, this did the trick in locating it.Anglicanism
R
17

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 service and try again it works for me Hope Its Works for You also.enter image description here

Rhino answered 2/4, 2016 at 8:25 Comment(4)
The answer was provided previously. Dont get any reason post it againSpadix
buddy am facing same problem but i do not know hot open services window then i found a way and i thought share with peopleRhino
Now another person @Debendra copied from your answer and got more votes than you.Kovach
what can I say on that.Rhino
M
15

I encountered the same problem In my case, I solved the problem in this way

Step 1: From start menu went to SQL server configuration manager

Step 2: Enabled TCP/IP

enter image description here

Step 3: Double clicked TCP/IP and went to IP Address last entry IP ALL and entered TCP Port 1433 then applied

enter image description here

Step 4 : then pressed win+r and wrote services.msc opened the Services then scrolled down then right clicked on SQL Server (MSSQLSERVER) choose restart

enter image description here

That resolved my problem. Even if doing all of the above steps do not solve the problem then simply restart the PC then hopefully it will work.

Maisel answered 2/7, 2020 at 9:5 Comment(2)
This is the same answer as @Jaw above, answered about 4 years before on July 28 2016. And upvoted for just copying.Kovach
I faced the same problem more than a year ago and solved it in this way thus, I shared this.Maisel
C
14

This solution resolves both issues Network Error & service behind SQL server

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

To begin - there are 4 issues that could be causing the common LocalDb SqlExpress Sql Server connectivity errors SQL Network Interfaces, error: 50 - Local Database Runtime error 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 enter image description here
  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"

Restart MSSql Server or Simply restart your machine!

  • Hold/Press to open the CMD, window + R and Type "services.msc"

  • Now look for sql server services, open find SQL SERVER with instance name then ReStart this service and try again

SqlLOCALDb_edited.png

Continuate answered 1/3, 2017 at 5:17 Comment(0)
P
10

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

Placentation answered 8/10, 2015 at 10:6 Comment(2)
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.Duplication
Why is everyone here assuming it's a local database????Doherty
H
10

After doing everything mentioned here:
http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-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.

Hedron answered 27/2, 2016 at 17:47 Comment(0)
P
10

I am using SQL Server 2016 and Window 10.

enter image description here

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. enter image description here

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

enter image description here

The following procedures configure the Windows Firewall by using the Windows Firewall with Advanced Security Microsoft Management Console (MMC) snap-in. The Windows Firewall with 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

Porbeagle answered 11/11, 2016 at 7:6 Comment(2)
On my PC Windows 10 the sql server instance is at C:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL\Binn\Sqlservr.exeCheery
There are many ways to block SQL Server from being accessed. The SQL Browser should get around it but turning it off and then checking what is listed above, narrows down the issue to login permission, TCP Port access through the firewall and that assumes remote connections are allowed. Remote connections are default so the two main issues are the Port access (like 192.168.1.2,60122) where the port for the instance is 60122, and the firewall rule. Thanks Fred.Manlove
O
8

You can test the following methods.

  • a

    1. Check the connection string of the project.
  • b

    1. Go to services and restart SQLServer Instance.
  • c

    1. Open 'SQLServer Configuration Manager'
    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
  1. Then in the middle tab double click the found item(Instance) or created item of 'SQL 1433 Port' name by you.
  2. Select 'Scope' tab in opened dialog box(SQL Server Properties)
  3. In the Local PC Go to google.com in your Browser and search 'My IP'.
  4. then copy of your 'IP'
  5. 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
  6. In the opened dialog box(IP Address) select 'This IP Address or Subnet' option and paste your 'IP', click OK button.
Osiris answered 30/3, 2017 at 7:15 Comment(0)
H
6

I have to run SQL Server Browser service into SQL Server Configuration Manager. Installation can't discover newly created service without this.

Handrail answered 27/1, 2016 at 11:11 Comment(2)
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)Hengel
note after your command, this resulted in server name on a local machine Start > Run > cmd > sqlcmd -LHengel
W
6

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 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!

Walcott answered 26/5, 2016 at 14:52 Comment(0)
B
5

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

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.

Bedrabble answered 15/10, 2016 at 18:22 Comment(0)
D
5

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.

The same issue was 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 another 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)"

Duchamp answered 17/1, 2017 at 9:55 Comment(0)
M
5

You may check service status of MS SQL Server 2014. In Windows 7 you can do that by:

  1. Go to search and Type "SQL Server 2014 Configuration Manager
  2. Then click on "SQL Server Service" on left menu
  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
Mitchiner answered 16/7, 2017 at 7:36 Comment(0)
B
5

I encountered this problem after i changed the name of my computer. So i simply had to update the Server Name in SQL Server Management Studio:

"Server name" -> "Browse for more..." -> "Database Engine" -> Choose "[Your computer name]" -> "OK"

Biocellate answered 11/5, 2022 at 20:39 Comment(0)
S
4

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 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.

Septillion answered 28/4, 2016 at 7:51 Comment(1)
Happened to me as well. Should have checked that before checking trying to diagnose the firewall. I had the right connection string, but I was running the the wrong project in the solution...Mongrel
T
4

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

enter image description here

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.

Thinnish answered 20/2, 2017 at 22:29 Comment(1)
Also do not make the silly mistake of using / instead of \ in the connection string.Bal
D
4

When I experienced this error in Visual Studio,

“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
                    }
                }
            }
        }

It was inexplicable because the SQL query was very simple, I had the right connection string, and the database server was available. I decided to run the actual SQL query manually myself in SQL 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!)

Denim answered 22/5, 2017 at 20:50 Comment(1)
This is great and very helpful.Kovach
S
4

Summary

To fix this issue encountered while running local app vs remote database, use SQL Server 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.

enter image description here

Shoer answered 2/11, 2017 at 14:0 Comment(0)
D
4

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

  • New a connection

enter image description here

  • Select ur server name

enter image description here

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

Dias answered 14/11, 2017 at 10:57 Comment(1)
This helped me find that I needed to REMOVE the port number for a LocalDB connection string, when using Entity Framework.Edh
C
4

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

Callimachus answered 7/6, 2018 at 13:44 Comment(0)
F
4

In my situation MSSQLSERVER service had a problem so I restarted the service and problem solved.

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.

Faustofaustus answered 7/7, 2019 at 8:15 Comment(2)
More than 3 people have given this same answer, and some even with screenshots before your answer.Kovach
Also your last statement "if disabled click on Restart" is incorrect. If it is disabled you can't restart. You need to change the disabled status to Manual or Automatic, and then "Start" the service.Kovach
Q
4

Just restart SQL Server (MSSQLSERVER) service.

Quittor answered 26/12, 2020 at 22:58 Comment(1)
More than 4 people have given this same answer, and some even with screenshots before your answer.Kovach
B
4

For remote server database connection. If non of the answers satisfy you it is most likely that you haven't added SQL Port 1433 to Windows Firewall Exceptions. Do the following steps.

  1. Go to Start Menu open Run type WF.msc.
  2. In Windows Firewall with Advanced Security.
  3. Add Inbound Rule.
  4. Add port 1433.
  5. Name your rule.
  6. Restart your SQL services.

For complete guide to problems in connecting remote server. Troubleshoot connecting to SQL Server Database.

Binnie answered 26/1, 2022 at 13:29 Comment(0)
A
3

If you're encountering this while debugging in Visual Studio, make sure that the project build path points to a local drive, or follow these steps to grant permissions to the network folder.

Affixation answered 16/11, 2016 at 0:20 Comment(0)
C
3

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.

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

Also, to test connectivity from a server where SQL server client is NOT present,

--> 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.

Claudioclaudius answered 15/3, 2017 at 21:35 Comment(0)
R
3

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.

  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.
Realpolitik answered 24/4, 2017 at 3:33 Comment(0)
S
3

Xml tag arrangement in Web.config is important

First

<configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>

After

<connectionStrings>
  <add name="SqlConnectionString" connectionString="Data Source=.; Initial Catalog=TestDB; Trusted_Connection=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
Syracuse answered 25/12, 2017 at 8:52 Comment(0)
S
2

This error occurs when your sql server instance is stopped.

GO to all Programs>SQL Server >Configuration tools>SQL SERVER CONFIGURATION 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;)

Stratosphere answered 16/4, 2016 at 12:58 Comment(0)
B
2

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.

Botryoidal answered 22/10, 2016 at 20:34 Comment(0)
K
2

I also faced to this kind of problem even if I use the correct credentials. Please make sure to execute the following actions.

Make sure your credentials for the sql server. In sql server field you have to use the computer name. enter image description here

To find the computer name, search on your computer as computer name, then you can find the computer name. Then paste it and try to connect.

If it is not working, try to start the sql server on your computer from services. Below screenshot will be helpful.

enter image description here

Kemppe answered 19/12, 2022 at 4:4 Comment(1)
An update to my machine by my IT department changed my Computer's name. Nobody told me this was going to happen. I spent way too long trying to find a much more complex reason for my not being able to access my own SQL Server Express server only to find out that the SERVER which is my local PC was changed without my knowledge.Audiology
I
1

It seems that your instance of localdb is not running. To start it on computer startup, add into your Start menu \ Startup folder BAT file with following line

sqllocaldb start name_of_instance

where name_of_instance is name of localdb instance, which you want to start. You can list available instances in command line using sqllocaldb i.

e.g. If you're using SQL Server Management Studio and connecting to Server Name (localdb)\v11.0, then your BAT file will look like

sqllocaldb start v11.0
Incubation answered 9/2, 2017 at 10:26 Comment(0)
Z
1

My issue was that you need to have a connection string entry in both your repository layer and web layer. Once I added it to my web.config as well as my app.config, Entity Framework was able to create the migration.

My question is why, does the web.config need it, when there is absolutely no database access there.

Zaragoza answered 28/2, 2017 at 20:58 Comment(0)
S
1

For me, the solution was to call the internet provider to open port 1433.

For some reason, they were blocking the port, and I couldn't even ping the database server (hosted on Azure). 100% of the packets were lost.

After they opened the port everything worked smoothly again.

Stillhunt answered 7/9, 2021 at 9:11 Comment(0)
D
1

I got Solution for me when trying to access mssql server from other network :

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

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

Enter "TCP Port" 1433

enter image description here

Add inbound+outbound rule for port 1433

Disharoon answered 22/1, 2022 at 12:33 Comment(0)
C
1

I had the same issue after upgrading my Windows to Windows Pro 10 21H2. I have two SQL instances - 2014 and 2019 and I was not able to connect only to 2019 one. I restarted the computer, restarted all SQL related services. Two of the services were showing errors (SQL Server and SQL Server agent) and I was not able to start them. I could not also start these two services from C:\Windows\SysWOW64\SQLServerManager15.msc In the logs (C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER01\MSSQL\Log) I saw these lines:

Initializing the FallBack certificate failed with error code: 15, state: 29, error number: 0.
Error: 17190, Severity: 16, State: 1.
Unable to initialize SSL encryption because a valid certificate could not be found, and it is not possible to create a self-signed certificate.
Error: 17182, Severity: 16, State: 1.
TDSSNIClient initialization failed with error 0x80092004, status code 0x80. Reason: Unable to initialize SSL support. Cannot find object or property. 
Error: 17182, Severity: 16, State: 1.
TDSSNIClient initialization failed with error 0x80092004, status code 0x1. Reason: Initialization failed with an infrastructure error. Check for previous errors. Cannot find object or property. 
Error: 17826, Severity: 18, State: 3.
Could not start the network library because of an internal error in the network library. To determine the cause, review the errors immediately preceding this one in the error log.
Error: 17120, Severity: 16, State: 1.
SQL Server could not spawn FRunCommunicationsManager thread. Check the SQL Server error log and the operating system error log for information about possible related problems.

It turned out that after the upgrade the "Log On" property (second tab on service properties) of the service was set to NT AUTHORITY\NETWORK SERVICES. When I changed it to "Local System Account" I was able to start the service and connect to the MS SQL 2019 instance.

This msdn forum post has helped me to find this.

Cameliacamella answered 10/3, 2022 at 10:53 Comment(0)
C
1

If you are removing migrations, you should check your ConnectionString.

Carolincarolina answered 23/4, 2022 at 11:39 Comment(0)
I
1

Faced the similar problem. For me, the appsettings.Production.json file was not being used by production server and the application was using appsettings.json file. Environment Variable in the system was not set to Production. It was directing requests to a different server overall.

Indeed answered 21/6, 2022 at 3:19 Comment(0)
E
1

If Tomcat server or any server you are using is down then this error might occur.

Ezekiel answered 23/9, 2022 at 11:29 Comment(0)
R
1

I got this error after working at distance (VPN) for a few years. At some point in time I must have changed my DNS settings to the IP address of my home router. Now I was (again) in the same network as the server, and got the error above. the solution was to open "Network status" / "Change adapter options" and right click the active internet connection (Ethernet in my case) to get to the properties of IPv4. Under "Use the following DNS server addresses" I entered the local IP address of my server, and what do you know...! The computer contacted the domain (on the server) and SQL Server opened up.

To check if you have the same problem, open cmd and enter nltest /dsgetdc:domainname [exchange "domainname" with the name of your domain] If you get a message saying "Getting DC name failed: Status = 1355 0x54b ERROR_NO_SUCH_DOMAIN" you either got the domain name wrong, or you may have this problem.

Rubinrubina answered 1/11, 2022 at 14:38 Comment(0)
I
1

after tried all answers, i put in port number(1433) after servername with comma into connection string worked for me. Its in below :

"Server=**.***.***.*\\MYSERVER,1433;Database=****;User Id=****;Password=*****;MultipleActiveResultSets=true;TrustServerCertificate=True"
Impressionable answered 9/1, 2023 at 12:10 Comment(0)
M
1

FOR AZURE VM USERS

I have tried all of the above (so those still might be valid) but still didn't wotk.

IMPORTANT: Mine was a just a playground server so security was really not a concern. So do your research, this is just a workaround, and not a prod-safe approach.

Make sure you can ping your server. In my case, I was able to RDP but cannot ping my server on Azure. I was keep getting Request timed out. Beacuse seems Azure blocks ICMP protocol by default.

You can add a rule to firewall. In my case, regardless what I have added through the firewall on that machine, nothing changed. Thanks @John for the above answer, that reminded me too that I have to add this from the Networking on Azure Portal.

As soon as I added a rule for port 0, then finally I was able to connect remotely.

this link this link was also helpful.

enter image description here

Millar answered 7/2, 2023 at 6:6 Comment(0)
B
1

I ran on a similar problem while using MS SQL 2022. When initially installed I was able to access the database using MSSQL Management Studio, but after the computer restart the SQL Server engine won't start automatically. In my case it was the account used to logon, the default account is MSSQLSERVER. I changed the account to my computer account (or domain account, if you are on a corporate environment)... on the Computer Management >> Services and Applications >> SQL Server >> right click >> Properties >> Log On >> This account >> enter userid password and confirm password. Then click the start button to start database engine.

Beatific answered 19/7, 2023 at 15:56 Comment(0)
B
1

Windows Server 8 R2 and SQL Server 8 R2

I Just Restared my Server PC And Issue resolved.

Bimolecular answered 19/10, 2023 at 6:38 Comment(0)
T
1

My issues was that I was using localhost/12.7.0.0.1 to connect but it was disabled in Sql Server Configurations.

Open Server Confuguration Manager -> SQL Server Network Configuration -> Protocols for MSSQLSERVER -> TCP/IP (Make sure this is enabled) ->Properties -> Enable

You will need to restart the server for changes to take effect. enter image description here

Tullusus answered 15/11, 2023 at 10:48 Comment(0)
S
0

It could also be as simple as the fact that your database is not actually MS SQL Server. If your database is actually MySql, for instance, and you try to connect to it with System.Data.SqlClient you will get this error.

By far most examples of ADO.Net will be for MSSQL and the inexperienced user may not know that you can't use SqlConnection, SqlCommand, etc., with MySql.

While all ADO.Net data providers conform to the same interface, you have to use the provider made for your database.

Spinal answered 19/5, 2019 at 20:44 Comment(0)
C
0

I also had this issue, I tried everything which suggested in this post but nothing worked. Finally I solved my issue by executing this query in my SQL Server

EXEC sp_configure 'remote access', 0 ;  
GO  
RECONFIGURE ;  
GO  
Cygnus answered 27/6, 2019 at 5:20 Comment(0)
E
0

I know this is buried, but I had caused this issue when I moved a database without giving the NT Service\MSQLSERVER account rights to the directory I moved the database files to. Giving the rights and restarting SQLServer did the trick.

Erv answered 3/9, 2019 at 15:6 Comment(0)
D
0

Verify the account you are using to create a session for the SQL Server instance.

See

Detest answered 9/10, 2020 at 11:35 Comment(0)
B
0

If SQL Server is running and you still get an error; When SQL Server is opened, instead of the default server name which is displayed you should select the server name ending with \SQLEXPRESS under the Server name-> Browse for more-> Database engine option.

Britain answered 18/1, 2021 at 0:21 Comment(0)
C
-1

I have tried almost everything. Then, I have uninstalled Malwarebytes. A software which claims that it can remove malware (often it can). After that, all is fine. Maybe somebody might run into the same issue for the same reason.

Cabrales answered 12/12, 2019 at 19:32 Comment(1)
Very unlikely that this is related.Ptolemaic
A
-1

I came here so late with the same problem. For me the problem came coz I changed the pc name.

Appoggiatura answered 13/1, 2022 at 12:59 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.