An attempt was made to access a socket in a way forbidden by its access permissions
Solution 1
I had a similar issue with Docker for Windows and Hyper-V having reserved ports for its own use- in my case, it was port 3001
that couldn't be accessed.
- The port wasn't be used by another process- running
netstat -ano | findstr 3001
in an Administrator Powershell prompt showed nothing. - However,
netsh interface ipv4 show excludedportrange protocol=tcp
showed that the port was in one of the exclusion ranges.
I was able to follow the solution described in Docker for Windows issue #3171 (Unable to bind ports: Docker-for-Windows & Hyper-V excluding but not using important port ranges):
-
Disable Hyper-V:
dism.exe /Online /Disable-Feature:Microsoft-Hyper-V
-
After the required restarts, reserve the port you want so Hyper-V doesn't reserve it back:
netsh int ipv4 add excludedportrange protocol=tcp startport=3001 numberofports=1
-
Reenable Hyper-V:
dism.exe /Online /Enable-Feature:Microsoft-Hyper-V /All
After this, I was able to start my docker container.
Solution 2
Just Restart-Service hns
can change the ports occupied by Hyper-V. It might release the port you need.
Solution 3
Per this link:
the symptom could occur if the replication service tries to use the ports that occupied by others, or by a malfunction NIC. Please try the following steps:
- Restart the windows firewall service
- Reboot the problematic machine
- Restart the “TCP/IP stack”. Run CMD as administrator, type “netsh int ip reset resetlog.txt” to reset TCP/IP.
- Try to temporarily disable antivirus.
Solution 4
Not surprisingly, this error can arise when another process is listening on the desired port. This happened today when I started an instance of the Apache Web server, listening on its default port (80), having forgotten that I already had IIS 7 running, and listening on that port. This is well explained in Port 80 is being used by SYSTEM (PID 4), what is that? Better yet, that article points to Stop http.sys from listening on port 80 in Windows, which explains a very simple way to resolve it, with just a tad of help from an elevated command prompt and a one-line edit of my hosts file.
Solution 5
My windows firewall was blocking port 8080 so i changed it to 5000 and it worked!
Jerry
Updated on July 09, 2022Comments
-
Jerry almost 2 years
I have a website on HostGator and a dedicated server of my own running SQL Server 2008R2. The connection string I use is X.X.X.X,1433 which points to the IP address of my dedicated server. I have made the firewall settings on my server so that I can use SSMS & log into SQL Server from my home PC.
Having done that, I was under the impression that connecting to SQL from my hostGator hosted-site would work just fine. I receive the following error:
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: TCP Provider, error: 0 - An attempt was made to access a socket in a way forbidden by its access permissions.)
I have looked up this error and found many explanations, but not one dealing with my circumstances. My server is running Windows 2008 w/IIS 7.5. I was assured by HostGator tech support that there would be no problems from their end.]]
My firewall allows TCP port 1433, & the UDP port 1434 for the SQL Server Browser service.
Since I have a dedicated server, I have no one to ask this question to from my hosting company.
-
Jerry about 11 yearsSorry for the delayed response @Jason...Found this link: support.microsoft.com/kb/968872?wa=wsignin1.0 and used the accompanying instructions to re-do the firewall settings on my server. Now, thankfully, it's working!
-
RugerSR9 over 7 yearsMcAfee antivirus blocks port 25 by default, "to prevent mass mail attacks".
-
Antfish almost 7 yearsBitdefender also blocked the port in question
-
Henrik Staun Poulsen over 6 years@RugerSR9; you are right. I had to add Databasemail.exe (for SQL Server 2016) to the exclude list to get mails to go out. Thank you for posting.
-
AJ Henderson about 5 yearsThis also applies if you are using Hyper-v and have the Hyper-V bridge enabled. Note that a reboot is required after disabling the bridge.
-
MacGyver about 3 yearsYou can manually set the port by going to system tray > PgAdmin > Configure > Runtime tab > Fixed Port Number and Port. Ideally, this port should be set to be within the en.wikipedia.org/wiki/Ephemeral_port range to avoid a conflict. Check availability here. en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
-
Timothy Macharia about 3 yearsThanks mate. For me, running only step no. 3 and restarting my machine worked.
-
killshot13 about 3 yearsThank you for this handy bit; it turned out to be a lifesaver.
-
AbhiAbzs about 3 yearsThis worked only when my hyper-v was disabled, as soon as I turned on hyper-v again, I started getting the same error. Running this in admin pwsh worked for me
Restart-Service hns -f
-
ladenedge about 3 yearsOne particular solution in the linked Github issue worked for me without worrying about specific ports:
net stop winnat
. -
sfuqua almost 3 yearsEasy & effective solution for me.
-
zeroFruit almost 3 yearslinks are broken
-
Mohammad Amin Purmoradian over 2 yearsThank you. It worked for me and fixed my issue.
-
Chrissy LeMaire over 2 yearsSo simple and effective, thanks!
-
Yusuff Sodiq about 2 years@AbhiAbzs that command worked for me too but I had to run it twice. I had issues with 3 ports, the first run of the command fixed 2 of them and the second run fixed the rest. I observed that the exclusion ranges changes per restart. Before anyone thinks this command doesn't work for them, ensure to run the command below to see the exclusion range after restart.
netsh interface ipv4 show excludedportrange protocol=tcp