Unable to connect to SQL Server instance remotely

217,350

Solution 1

  • To enable mixed authentication you can change the following registry key:

    HKLM\Software\Microsoft\Microsoft SQL Server\MSSQL.1\MSSQLServer\LoginMode
    

    Update the value to 2 and restart the Sql Server service to allow mixed authentication. Note that MSSQL.1 might need to be updated to reflect the number of the SQL Server Instance you are attempting to change.

  • A reason for connection errors can be a virus scanner installed on the server which blocks sqlserver.exe.

  • Another reason can be that the SQL Server Browser service is not running. When this service is not running you cannot connect on named instances (when they are using dynamic ports).

  • It is also possible that Sql Server is not setup to listen to TCP connections and only allows named pipes.

    1. In the Start Menu, open Programs > Microsoft SQL Server 2008 > Configuration Tools > SQL Server Surface Area Configuration
    2. In the Surface Area Configuration utility, click the link "SQL Server Configuration Manager"
    3. Expand "SQL Server Network Configuration" and select Protocols.
    4. Enable TCP/IP. If you need Named Pipes, then you can enable them here as well.
  • Last but not least, the Windows firewall needs to allow connections to SQL Server

    1. Add an exception for sqlserver.exe when you use the "Dynamic Port" system.
    2. Otherwise you can put exceptions for the SQL Server ports (default port 1433)
    3. Also add an exception for the SQL Server Browser. (udp port 1434)

More information:

As a last note, SqlLocalDB only supports named pipes, so you can not connect to it over the network.

Solution 2

In addition to configuring the SQL Server Browser service in Services.msc to Automatic, and starting the service, I had to enable TCP/IP in: SQL Server Configuration Manager | SQL Server Network Configuration | Protocols for [INSTANCE NAME] | TCP/IP

enter image description here

Solution 3

  1. Launch SQL Server Configuration Manager on your VPS.

  2. Take a look at the SQL Server Network Configuration. Make sure that TCP/IP is enabled.

  3. Next look at SQL Server Services. Make sure that SQL Server Browser is running.

  4. Restart the service for your instance of SQL Server.

Solution 4

Disable the firewall and try to connect.

If that works, then enable the firewall and

Windows Defender Firewall -> Advanced Settings -> Inbound Rules(Right Click) -> New Rules -> Port -> Allow Port 1433 (Public and Private) -> Add

Do the same for Outbound Rules.

Then Try again.

Solution 5

I had the same issue where my firewall was configured properly, TCP/IP was enabled in SQL Server Configuration Manager but I still could not access my SQL database from outside the computer hosting it. I found the solution was SQL Server Browser was disabled by default in Services (and no option was available to enable it in SQL Server Configuration Manager).

I enabled it by Control Panel > Administrative Tools > Services then double click on SQL Server Browser. In the General tab set the startup type to Automatic using the drop down list. Then go back into SQL Server Configuration Manager and check that the SQL Server Browser is enabled. Hope this helps. enter image description here

Share:
217,350
Leah
Author by

Leah

Updated on May 19, 2021

Comments

  • Leah
    Leah almost 3 years

    I’m trying to access the SQL Server instance on my VPS from SQL Server Management Studio on my local machine. It’s not working (the error I’m getting is:

    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.

    I think this is because I need to configure the database engine to allow remote connections (correct me if I’m wrong!). So I’ve found this step-by-step guide to help me do that: http://www.linglom.com/2009/03/28/enable-remote-connection-on-sql-server-2008-express/ I’ve got to point 10 in the guide and I am now stuck! I don’t have SQL Server Management Studio installed on my VPS. Anyway, this has left me with two options:

    1. Install SSMS
    2. Find another way to do point 10 onwards in the guide without having SSMS installed

    I tried installing SSMS on my VPS using the Web Platform Installer but it keeps failing. I don’t know why it’s failing because it doesn’t seem to give a reason why. Does anyone know how I could allow remote connections a different way?

    The version of SQL Server installed on my VPS is SQL Server 2008 R2 Express.

    Update:

    I have tried to disable the firewall on both my laptop and VPS to see if it is a firewall issue. This made no difference to the error message.

    Another Update:

    Having now been able to install SSMS (I installed directly from the website rather than using the WPI), I have been able to check that the server is configured to allow remote connections (I went to SSMS, connected to the SQL Server instance, right-clicked on the connection, clicked Properties, went to the Connections tab. "Allow remote connections to this server" is already ticked).

    SOLUTION

    Thanks to everyone for helping me get to this solution! I've finally managed to get it to work! I followed Filip De Vos's advice and opened the ports in the Firewall on my VPS and then I received a different error message. This led me to investigate further and I found that I was using the wrong credentials to login! So I've set a password for the sa user and I've managed to login using that! Thanks again!

  • Leah
    Leah over 12 years
    Thanks for your help. However, I've already tried all those steps as detailed in the link in my question. I've got that far and the error message is still appearing.
  • JYelton
    JYelton over 12 years
    Ah, sorry I didn't realize the link had the same basic steps. You don't need SSMS necessarily because it is essentially a client application that connects to the server to allow you to execute queries and manage database tables, etc. If the server instance is set to not allow windows authentication (covered by steps 10-12) you will need to know the sql user/pw combo to connect. I'm not sure you can change the login method without SSMS.
  • JYelton
    JYelton over 12 years
    Leah just FYI SQL Server always allows windows authentication, but sql user authentication can be enabled/disabled. (Per How can I disable the windows authentication mode of SQL Server). Good luck.
  • Leah
    Leah over 12 years
    So I can't connect with my normal remote desktop details then? I haven't set up any details to connect to the SQL Server instance because the SSMS installation fails as well! Is SSMS Express not compatible with SQL Server 2008 Express R2 or is there no reason you are aware of why the installation should fail? Thanks for bearing with me!
  • JYelton
    JYelton over 12 years
    You should be able to connect using SSMS on your local workstation, using Windows credentials. My recommendation to make life easier is to post a question on serverfaul or superuser with the exact error messages you get when trying to install SSMS and try to get that to work. Configuring the SQL Server will be much easier then. To answer your question, SSMS Express should work just fine with SQL Server Express.
  • Leah
    Leah over 12 years
    Thanks. I didn't get much of an error message when trying to install SSMS but I'll try again and post the error message as you've suggested.
  • Leah
    Leah over 12 years
    I have managed to install SSMS on my VPS now - I still can't seem to connect to the VPS instance from my local machine though. Do you have any ideas?
  • Tao
    Tao over 12 years
    Wouldn't this report a login failure rather than network/connection error?
  • Filip De Vos
    Filip De Vos over 12 years
    @Tao Added additional steps to take to allow incoming connections
  • Leah
    Leah over 12 years
    @Filip De Vos Thanks very much for your suggestions. Would you please be able to explain how I could add "exceptions for the SQL Server ports" with regards to the Firewall?
  • Filip De Vos
    Filip De Vos over 12 years
    @Leah see the "How to: Configure a Windows Firewall for Database Engine Access" link I added
  • Leah
    Leah over 12 years
    @Filip De Vos Apologies - I must have been adding my comment as you added those links. Thanks - I'll take a look now.
  • Leah
    Leah over 12 years
    @Filip De Vos I've followed instructions in your first link to open the two ports for SQL Server instance and SQL Server Browser service and I'm now getting a different error when I try to connect: "Cannot connect to [server].Login failed for user [user]"
  • bgmCoder
    bgmCoder about 11 years
    This solved my problem too - thank you! I had neglected both the SQL Server Browser on my local machine as well as the clearing of the UDP Port 1434 for the SQL Server Browser service in the firewalls of both machines. Now VS connects!
  • early
    early almost 10 years
    "3. Also add an exception for the SQL Server Browser. (udp port 1434)" This works perfectly for me! Thanks.
  • Shahdat
    Shahdat about 7 years
    After all restart SQL Server service
  • jkell311
    jkell311 over 2 years
    Praise 🙏🏻 I spent 15 minutes trying to find my password to this site just to upvote this answer