Google App Engine Flexible C# Connection to Cloud SQL SQL Server problem when deploying

342 views Asked by At

I have this problem when trying to deploy to AppEngine. On local machine using proxy it works fine.

Microsoft.EntityFrameworkCore.Database.Connection[20004]
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server)
An error occurred using the connection to database 'dblivtron' on server 'cloudsql'.

My config:

Appengine Flexible API = enabled
Cloud SQL Admin API = enabled
Instance public address = enabled

Instance Connection Name: livtron-testproject:europe-west1:livtrondbinstance
Database: dblivtron

My app.yaml:

runtime: custom
env: flex
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10
beta_settings:
  cloud_sql_instances: livtron-testproject:europe-west1:livtrondbinstance=tcp:3306'

My connection string in appsettings.json

"ConnectionStrings": {
    "DefaultConnection": "Server=cloudsql;Database=dblivtron;User Id=sqlserver;Password=#####;MultipleActiveResultSets=true;Encrypt=false;Pooling=true;"
  }
1

There are 1 answers

0
Krzysztof Patra On

I found that the error I was getting was a little misleading. I worked when I removed MultipleActiveResultSets=true from connectionstring. I had to correct my code as well to help the MARS problems in aplication. But now it works.