Cloud Run unable to connect to Cloud SQL

Hi everyone,

I'm trying to set up a demo project. The basic setup is a Cloud Run istance, based on .NET, and a Cloud SQL instance, running Postgres. 

The issue is that cloud run can't connect to SQL

I'm still not familiar with all the environment, so i hardcoded the public IP address of the SQL inside the .NET app.

I have:

  • added the SQL connection to it inside the cloud run settings
  • added 0.0.0.0/0 and 0.0.0.0/24 as networks of the cloudrun settings
  • added HOST 0.0.0.0 in the dockerfile and in cloud run environment settings

But still, can't connect. The fun part is that from pgAdmin, locally from my pc, i can connect to SQL.

Inside the cloud run log i see the error:

---> System.Net.Sockets.SocketException (99): Cannot assign requested address /cloudsql/<PROJECT>:europe-west9:<PROJECT>-db/.s.PGSQL.5432

I never coded that part of the connection string anywhere, nor in the code nor in environment settings, so i guess is some sort of DNS provided by Google

The thing is, that db doesn't even exists anymore. I dropped the whole instance and rebuilt it due to changes in Db structure. I tought a fresh start was easier so early in development.

Any ideas?

PS: i would add more specific tags to this post but seems like they don't exists

0 1 437
1 REPLY 1

Hi there,

I'm also encountering a similar issue while setting up my demo project. I'm using Cloud Run with a .NET application and a Cloud SQL instance running Postgres. Like you, I've faced challenges connecting Cloud Run to SQL.

I've tried several steps, including adding the SQL connection in the Cloud Run settings, specifying networks in the Cloud Run settings, and setting the host to 0.0.0.0 in both the Dockerfile and Cloud Run environment settings. Despite these efforts, I'm still unable to establish a connection. Interestingly, I can connect to the SQL instance from pgAdmin on my local machine.

In my Cloud Run logs, I'm seeing the following error:

---> System.Net.Sockets.SocketException (99): Cannot assign requested address /cloudsql/<PROJECT>:europe-west9:<PROJECT>-db/.s.PGSQL.5432

I haven't explicitly coded this part of the connection string in my code or environment settings, leading me to believe it might be related to some DNS provided by Google. Additionally, I've dropped the entire SQL instance and rebuilt it due to changes in the database structure, thinking a fresh start would be easier at this stage of development. However, the issue persists. Plz tell me as I have to work on my mod apk of capcut website.

If anyone has insights or solutions to this problem, I'd greatly appreciate the help. Thank you!