我在这里阅读了云SQL的文档,但在解决方案资源管理器中,我没有appsettings.json文件来放置以下代码:
{
"CloudSQL" : {
ConnectionString": "Host=127.0.0.1;Uid=DATABASE_USER;Pwd=PASSWORD;Database=DATABASE_NAME"
}
}
然后,在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);
我在Mac上的Visual Studio上使用iOS的空空白项目。如何连接到云SQL?
您可以在代码背后对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);
不建议从客户端直接连接到数据库服务器。这是不安全的。