简体   繁体   中英

How to connect Google Cloud PostgreSQL with C#

I created a managed sql instance on Google Cloud using these instructions .

I would like to connect from my code using 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.

What should be my connection string for the instance on 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#. 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. According the the MySQL Connector docs for C# (found here ), the connection string should look like the following:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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