简体   繁体   English

如何在 Visual Studio 上使用 Xamarin(iOS 项目)连接到 Cloud SQL

[英]How to connect to Cloud SQL using Xamarin (iOS project) on Visual Studio

I read the documentation on Cloud SQL here but in the solution explorer I not have appsettings.json file to put this code:我在这里阅读了 Cloud SQL 上的文档,但在解决方案资源管理器中我没有 appsettings.json 文件来放置此代码:

  {
  "CloudSQL" : {
     ConnectionString": "Host=127.0.0.1;Uid=DATABASE_USER;Pwd=PASSWORD;Database=DATABASE_NAME"
  }
}

Then, in your Startup.cs file, create a database connection:然后,在您的 Startup.cs 文件中,创建一个数据库连接:

var connectionString = new MySqlConnectionStringBuilder(
    Configuration["CloudSql:ConnectionString"])
{
    // Connecting to a local proxy that does not support ssl.
    SslMode = MySqlSslMode.None,
};
DbConnection connection =
    new MySqlConnection(connectionString.ConnectionString);

I use empty blank project for iOS on Visual Studio on Mac.我在 Mac 上的 Visual Studio 上使用 iOS 的空白项目。 How to connect to Cloud SQL?如何连接到云 SQL?

You can hard code the connectionString in code behind:您可以在后面的代码中对connectionString进行硬编码:

    var connectionString = new MySqlConnectionStringBuilder("Host=127.0.0.1;Uid=DATABASE_USER;Pwd=PASSWORD;Database=DATABASE_NAME")
    {
        // Connecting to a local proxy that does not support ssl.
        SslMode = MySqlSslMode.None,
    };
    DbConnection connection = new MySqlConnection(connectionString.ConnectionString);

Well, it is not recommend to connect directly to a db server from a client.好吧,不建议从客户端直接连接到数据库服务器。 It's unsafe.这是不安全的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Python 连接到云 SQL? - How to Connect to Cloud SQL using Python? 如何使用 Python 和私有 IP 从 GKE 连接到 Cloud SQL - How to connect from GKE to Cloud SQL using Python and Private IP 无法从 BigQuery 作业连接到不同项目中的 Cloud SQL Postgres - Unable to connect from BigQuery job to Cloud SQL Postgres in different project 如何通过 Kubernetes 连接到云 SQL - How to Connect to Cloud SQL Through Kubernetes 将 Visual Studio for Mac 中的 .NET 项目连接到 Azure SQL Edge - Connecting a .NET project in Visual Studio for Mac to an Azure SQL Edge 无法使用公共 IP 从 Cloud Composer 连接到 Cloud SQL - Cant connect to Cloud SQL from Cloud Composer using Public IP 如何从 Cloud Run 安全地连接到 Cloud SQL? - How to securely connect to Cloud SQL from Cloud Run? 如何将现有的 Google Cloud 项目连接到 Google Playstore 控制台用户? - How to connect an existing Google Cloud project to a Google Playstore console user? 无论如何,我可以通过 BigQuery 或 Data Studio 禁用公共 IP 连接到 Cloud SQL (SQL Server) 吗? - Is there anyway I can connect to Cloud SQL (SQL Server) with disabled public IP from BigQuery or Data Studio? Datastream 无法使用专用连接连接到具有专用 IP 的 Cloud SQL - Datastream can not connect to Cloud SQL with private IP using private connectivity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM