2
votes

I have a .NET Core 2.2 app using a PostgreSQL DB. Now I want to deploy it on Google Cloud App Engine Flex and Google Cloud SQL PostgreSQL.

I tried the official way and found this, where I found that you have to use $ gcloud beta app deploy instead of $ gcloud app deploy

My app.yaml configuration file:

env: flex
runtime: aspnetcore
beta_settings:
  cloud_sql_instances: "<SQL-NAME>=tcp:<PORT>"

The issue is that I get this error:

Trying to connect to Host=127.0.0.1;Port=XXX;Username=XXX;Password=XXX;Database=XXX; Application startup exception: System.Net.Sockets.SocketException (111): Connection refused

Do I have to include special libraries into .NET Core 2.2 to support Google App Engine?

1

1 Answers

1
votes

You don't need to include any special libraries in .NET Core 2.2 rather than those that are already included in the Quckstart that you have shared above, unless of course you are using any additional libraries in your code.

I have tried the quickstart and deployed my .NET GAE app that connects to CloudSQL PostgreSQL database.

Taking a look at your app.yaml configuration file I can see that there is an issue with it. Also based on the error message you are getting I assume that you are having an issue in your appsettings.json file as well.

Based on the quickstart of GitHub that you shared, the configuration when deploying should be:

app.yaml

runtime: aspnetcore
env: flex

beta_settings:
    cloud_sql_instances: "[PROJECT_ID]:[INSTANCE_REGION]:[INSTANCE_NAME]=tcp:[TCP_PORT_NUMPER]"
  • TCP Port number for PostgreSQL: 5432
  • TCP Port number for MySQL: 3306
  • To find the Instance connection name which is the part before tcp, you can go to Cloud Console > SQL > [YOU_INSTANCE_NAME] and you can find the entire string under Instance connection name

appsettings.json

{
  "CloudSQL" : {
    "Database" : "PostgreSQL",  // Set to "PostgreSQL" when using a PostgreSQL database.
      // [START gae_flex_mysql_settings]
    "ConnectionString": "Uid=[USER_ID];Pwd=[PASSWORD];Host=cloudsql;Database=[DATABASE_NAME]"
      // [END gae_flex_mysql_settings]
  }
}
  • Database should be PostgreSQL as also specified by the comment
  • ConnectionString should be filled with your own data that you used to setup the database
  • The Host part should be cloudsql when you are deploying and 127.0.0.1 when running locally.

127.0.0.1 indicates that the database is running locally and the cloudsql string indicates that it should use the connection string name. Based on the error, I assume that you used the 127.0.0.1 to test locally but then forgot to change it back when you were deploying.