简体   繁体   English

如何使用C#连接Google Cloud PostgreSQL

[英]How to connect Google Cloud PostgreSQL with C#

I created a managed sql instance on Google Cloud using these instructions . 我按照这些说明在Google Cloud上创建了一个托管sql实例。

I would like to connect from my code using C#. 我想使用C#从我的代码连接。

When I write locally, this is my connection string: 在本地编写时,这是我的连接字符串:

public string LocalDataSource = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='C:\Users\Bob\Desktop\versionsOfMediaPlayer\14.4.19\mediaPlayer_1\Database1.mdf';Integrated Security=True;Connect Timeout=30";

and I manage to write to local sql. 而且我设法写到本地sql。

What should be my connection string for the instance on Google Cloud? 我在Google Cloud上的实例的连接字符串应该是什么?

details of my instance: 我的实例的详细信息:

ip: <MY_IP_ADDRESS>
user: postgres
password: postgres
Instance connection name: my-project:us-central1:my-sql-instance

I added my local ip to the Cloud SQL instance firewall - so I manage to connect via command line, now I'd like to do so programmatically, using C#. 我将本地IP添加到了Cloud SQL实例防火墙-因此我设法通过命令行进行连接,现在我想使用C#以编程方式进行连接。 what should be my connection string? 我的连接字符串应该是什么?

Once you have authorized your IP address to connect, connecting to Cloud SQL is the same as any other database. 授权您的IP地址进行连接后,连接到Cloud SQL的方式将与其他任何数据库相同。 According the the MySQL Connector docs for C# (found here ), the connection string should look like the following: 根据C#的MySQL连接器文档(在此处找到),连接字符串应如下所示:

"server=<YOUR_IP_ADDRESS>;uid=postgres;pwd=postgres;database=your-database";

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM