Why am I getting “Cannot Connect to Server - A net

2018-12-31 00:14发布

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

Cannot connect to 108.163.224.173.

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) (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?

30条回答
时光乱了年华
2楼-- · 2018-12-31 00:49

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

查看更多
残风、尘缘若梦
3楼-- · 2018-12-31 00:50

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

查看更多
呛了眼睛熬了心
4楼-- · 2018-12-31 00:50

Press window + R (Run window Open) and in run window type "services.msc" and new services open find SQL SERVER(SQLEXPRESS) service start and try again it works for me Hope Its Works for You also.enter image description here

查看更多
看风景的人
5楼-- · 2018-12-31 00:50

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

查看更多
十年一品温如言
6楼-- · 2018-12-31 00:50

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.
查看更多
人间绝色
7楼-- · 2018-12-31 00:50

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.

查看更多
登录 后发表回答