asp.net - GCloud - 将 App Engine Flex 连接到其他项目中的 Cloud SQL

标签 asp.net google-app-engine google-cloud-platform google-cloud-sql

我正在尝试将我的 App Engine Flex 服务连接到共享项目中的云 SQL 数据库。

我已将 App Engine 默认用户和 App Engine Flex 用户作为 SQL 管理员添加到共享项目中。

现在我尝试使用以下连接字符串将应用程序引擎容器连接到云 sql 实例:

"Server=cloudsql;Database=cliche;User Id=user;Password=password;"

但是,使用给定的连接字符串,连接总是失败。

[13:57:37 ERR] An error occurred using the connection to database 'cliche' on server 'cloudsql'.
[13:57:37 ERR] An exception occurred while iterating over the results of a query for context type 'IKL.Data.ApplicationDbContext'.
 Microsoft.Data.SqlClient.SqlException (0x80131904): 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)

根据要求,我在此处提供了 app.yaml:

runtime: aspnetcore
env: flex
service: platform
manual_scaling:
  instances: 1
resources:
  cpu: 2
  memory_gb: 1.5
  disk_size_gb: 10
beta_settings:
  cloud_sql_instances: shared-resources-291914:europe-west3:edutec-mssql=tcp:1433  

最佳答案

我发现了你的问题!您的连接字符串 "Server=cloudsql;Database=cliche;User Id=user;Password=password;" 不正确。

Cloud SQL 代理打开隧道。隧道的一侧是 Cloud SQL 实例,另一侧是您的本地实例。因此您必须在本地主机上连接

"Server=127.0.0.1;Database=cliche;User Id=user;Password=password;"

关于asp.net - GCloud - 将 App Engine Flex 连接到其他项目中的 Cloud SQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64347601/

相关文章:

c# - 如何将 <xml></xml> 等 xml 标签格式更改为 <xml/>

c# - 如何启用迁移以在 MVC4 中更新我的数据库?

c# - ASP.NET:为无 cookie session 实现 ISessionIDManager?

javascript - Google 应用引擎上的服务器端 javascript

google-app-engine - Google API 用于定位,基于用户 IP 地址

google-cloud-platform - 如何将Cloud Armor与Kong集成?

c# - URL信息加密

database - 如何在 Appengine 中保留数据存储实体的版本历史

python - 如何在 git 上构建多个函数以在 Google Cloud Functions 上自动部署?

networking - Gcloud 实例无法 ping 另一个实例