在 C# 中连接云 运行 云 SQL 服务器实例

Connect Cloud Run to Cloud SQL Server Instance in C#

如果我理解 Cloud 运行 中的 "Cloud SQL Connections" 选项卡,应该实例化 Cloud SQL 代理。

我应该使用什么 sql 服务器连接字符串来完成这项工作?

设置:(都在同一个 GCP 项目中): 1. 创建 SQL 服务器的云 Sql 实例 2. 将您的 docker 图像上传到 Google Container registry。 使用 .netcore 编写,代码连接到步骤 1 中创建的 SQL 服务器 2. 在 Google Cloud 运行 中创建服务实例。 3. 从列表中指定云 SQL 连接和 select 您的 sql 服务器实例并部署。

没有使用云运行和SQL服务器试过这个但是...

  • 代理应在 127.0.0.1:1443 (link)

  • 上为您的 .NET 客户端建立连接
  • 假设您使用的数据库客户端类似于 Google example,您的连接字符串将是:

"ConnectionString": "User Id=[[USER]];Password=[[PASS]];Server=127.0.0.1;Database=[[DB]];"

如果我没理解错的话,默认端口是1443

NB 根据其他评论者,您的问题会随着更多细节得到改进。当您写到您正在完成步骤时,请附上链接。当您引用您的配置时,请包含片段。回答您问题的人受益于从问题中假设尽可能少的信息。

我认为它还不受支持。没有云 SQL 服务器的文档。

根据 official documentation :

Once correctly configured, you can connect your service to your Cloud SQL instance's unix domain socket using the format: /cloudsql/INSTANCE_CONNECTION_NAME.

Note: Cloud Run (fully managed) does not support connecting to the Cloud SQL instance using TCP. Your code should not try to access the instance using an IP address such as 127.0.0.1 or 172.17.0.1.

Also:

Note: The Cloud SQL Proxy does not support Unix sockets on Windows.

我尝试使用云 SQL 代理和 tcp 来做到这一点并得到:

 System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (111): Connection refused 127.0.0.1:1433