0

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.

TheGeneral
  • 79,002
  • 9
  • 103
  • 141
  • Possible duplicate of [How to connect Google Cloud SQL with C#](https://stackoverflow.com/questions/52457709/how-to-connect-google-cloud-sql-with-c-sharp) – Bradley Grainger Sep 22 '18 at 21:08

1 Answers1

1

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.
Bradley Grainger
  • 27,458
  • 4
  • 91
  • 108