C# SqlServer database connection problem while deploying to AppEngine

275 views
Skip to first unread message

Krzysztof Patra

unread,
Oct 5, 2020, 1:55:34 PM10/5/20
to Google App Engine
Hi
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
Data base: 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;"
  },

George (Cloud Platform Support)

unread,
Oct 5, 2020, 3:21:02 PM10/5/20
to Google App Engine
You mention a proxy? Is your local machine behind a proxy? That would be consistent with the error you keep receiving. Does the situation change if you access App Engine without a proxy, from another network?

It may be worthwhile having a look at Configuring Cloud SDK for use behind a proxy/firewall

Krzysztof Patra

unread,
Oct 5, 2020, 6:33:50 PM10/5/20
to Google App Engine
I think I found the real problem. It was connected to MultipleActiveResultSets=true. 
When I commented some code that was generating "the multiple batches on a single connection situation" on starting of the app, the deployment to Appengine got successful.
Does Google Cloud SqlServer have problem with it?   

Shawn Wu

unread,
Oct 7, 2020, 1:49:03 PM10/7/20
to Google App Engine
A batch is a SQL string that you send for execution to SQL Server. It can contain multiple statements. Every time you call SqlCommand.Execute* you send a single batch.
Reply all
Reply to author
Forward
0 new messages