0

I am trying to use visual studio to write a program in c# and have it connect to my google cloud sql server. Unfortunately I have been trying to troubleshoot it and have had no luck. I already added my IP and my connection works through MYSQL Workbench.

I attempted to connect with the whole data source, network library, initial catalog, etc. I tried it without the network library and used the proper way to escape \ in the string during the connection. I also tried the default 1433 port and 3306. No luck.

 // Build Connection String
            SqlConnection clearviscon = new SqlConnection(@"Server=xx.xx.xx.xx\alpine-park-243102:us-central1:xxx, 3306;Network Library=DBMSSOCN;Initial Catalog=xxdatabase;User ID=root;Password=xxx123");
            clearviscon.Open();
1
  • 2
    If you are really using MySQL you are using the wrong DB Provider. SqlConnection is for Microsoft SQL Server which is completely different from MySQL Jun 8, 2019 at 4:29

2 Answers 2

0

To connect to Google Cloud SQL for MySQL, you must use a MySQL client library. I recommend MySqlConnector.

Your connection string will be Server=xx.xx.xx.xx;Database=xxdatabase;User ID=root;Password=xxx123.

If you're using a client SSL certificate to connect to your server, add this to the end of your connection string: ;SslCa=server-ca.pem;SslCert=client-cert.pem;SslKey=client-key.pem.

0

You must use MySqlConnection.

See this link for more information: https://cloud.google.com/dotnet/docs/getting-started/using-cloud-sql

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.