Search code examples
sql-servergoogle-cloud-platformssmsgoogle-cloud-sdkgoogle-cloud-proxy

How to fix connectex error when trying to access SQL Server instance on Cloud SQL using SSMS via Proxy


What I'm trying to do

I am trying to manage my SQL Server instance on Cloud SQL (GCP) with SQL Server Management Studio (SSMS).

What I've done

I followed the steps in the Google Cloud documentation (here).
I followed steps 1-5 (condensed version below):

  1. Install Cloud SQL
  2. Run gcloud init
  3. Run gcloud auth login (P.S. I'm Owner on Project level)
  4. Download and install Google Cloud SQL Proxy (as per the instructions here)
    1. Enable Cloud SQL Admin API
    2. Install the proxy client (Windows PC for me, x64 - renamed file to cloud_sql_proxy.exe)
    3. Determine proxy authentication method (as per documentation here). I chose Cloud SDK since I need to download it in step 1 anyway
    4. Skip (not using service account authentication)
    5. Determine proxy instance specification (as per documentation here). Using Instances specified on proxy invocation method.
      • I only have private IP, so by default it will select the correct IP (as per documentation here)
    6. Same as step 5 (below) 5 . Start the proxy. I ran (in cmd) ./cloud_sql_proxy -instances=<INSTANCE_CONNECTION_NAME>=tcp:1433 (obviously replacing the <INSTANCE_CONNECTION_NAME> portion with my instance name.

At this point, everything seems to be working:

Listening on 127.0.0.1:1433 for <INSTANCE_CONNECTION_NAME>
Ready for new connections
New connection for <INSTANCE_CONNECTION_NAME>
New connection for <INSTANCE_CONNECTION_NAME>

Now following the instructions here, I attempt to connect to the database instance using SSMS (127.0.0.1, SQL Server Authentication, sqlserver, my super awesome password), Connect.

My issue

I now get the following error messages in the Cloud SDK window:

couldn't connect to <INSTANCE_CONNECTION_NAME>: dial tcp <PRIVATE_IP>:<PORT>: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Throttline refreshCfg(<INSTANCE_CONNECTION_NAME>: it was only called XXXs ago

(and it repeats a few times)

In SSMS I get the following prompt:

SSMS error message

My question

How do I fix this issue and properly connect to my database instance?


Solution

  • When setting the Connectivity settings for the SQL Server instance, I changed it to Private IP and unchecked the Public IP setting. Re-enabling the Public IP setting allowed me to establish a connection:

    Cloud SQL Connectivity settings

    External applications can still connect to the instance through the Cloud SQL Proxy

    This indirectly indicates to me that Cloud SQL Proxy needs the Public IP option to be enabled in order to establish a connection.