Connect Cloud Run to Cloud SQL Server Instance in C#

Viewed 1209

If I understand the "Cloud SQL Connections" tab in Cloud Run should instantiate the Cloud SQL Proxy.

What is the sql server connectionstring that I should use to make this work?

Setup : (All in the the same GCP Project): 1. Create a Cloud Sql instance of SQL Server 2. Upload your docker image to Google Container registry. Written using .netcore with code to connect to the SQL Server created in step 1 2. Create a Service instance in Google Cloud Run. 3. Specify Cloud SQL Connections and select your sql server instance from the list and deploy.

2 Answers

I've not tried this using Cloud Run and SQL Server but ...

  • The proxy should make a connection available to your .NET client on 127.0.0.1:1443 (link)

  • Assuming you're using a database client similar to the Google example, your connection string will be:

"ConnectionString": "User Id=[[USER]];Password=[[PASS]];Server=127.0.0.1;Database=[[DB]];"

If I understand correctly, the default port is 1443.

NB Per other commenters, your question would be improved with more details. When you write that you're completing steps, please include the links. When you reference your configuration, please include snippets. Folks answering your questions benefit from having to assume as little as information as possible from questions.

I do not think it is supported yet. There is no documentation for Cloud SQL Server.

According to the official documentation :

Once correctly configured, you can connect your service to your Cloud SQL instance's unix domain socket using the format: /cloudsql/INSTANCE_CONNECTION_NAME.

Note: Cloud Run (fully managed) does not support connecting to the Cloud SQL instance using TCP. Your code should not try to access the instance using an IP address such as 127.0.0.1 or 172.17.0.1.

Also:

Note: The Cloud SQL Proxy does not support Unix sockets on Windows.

I tried to do it using Cloud SQL Proxy with tcp and got:

 System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (111): Connection refused 127.0.0.1:1433
Related