user8210624
user8210624

Reputation:

Google Cloud Sql Connection with ssl in c#

I want to connect my google cloud SQL Server with SSL in c#. But I'm getting a Argument Exception error for "driver, sslca, sslcert and sslkey" keywords.

How can I connect my database to use SSL?

 string connStr = "Driver={MySQL ODBC 5.2 ANSI Driver}; Server=35.148.120.30; User = myuser; Password = mypass; sslca = ../sql_pem/server-ca.pem; sslcert = ../sql_pem/client-cert.pem; sslkey = ../sql_pem/client-key.pem; sslverify = 1; Option = 3; ";
 MySqlConnection conn = new MySqlConnection(connStr);
 MySqlCommand cmd;
 string s0;

 try
 {
     conn.Open();
     s0 = "CREATE DATABASE IF NOT EXISTS `hello97`;";
     cmd = new MySqlCommand(s0, conn);
     cmd.ExecuteNonQuery();
     conn.Close();
  }
  catch (Exception es)
  {

  }

Error

An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll

Additional information: Keyword not supported.

Upvotes: 0

Views: 888

Answers (1)

Bradley Grainger
Bradley Grainger

Reputation: 28207

Assuming you're using Connector/NET, the valid connection string options are listed here:

  • Driver - don't need this; it's implied by the library/class you're using
  • sslca - not supported by Connector/NET, but if you switch to MySqlConnector you can use CACertificateFile
  • sslcert, sslkey - convert these to a pfx file as described here then use the CertificateFile option.

Upvotes: 1

Related Questions