Search code examples
google-cloud-sqlgoogle-cloud-runcloud-sql-proxy

Connect Cloud Run to Cloud SQL Server Instance in C#


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.


Solution

  • 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