One of the topics for the MySQL 5.6 Developer exam is: "Write a basic .NET application that uses MySQL".
I have used Connector/Net a few times the last few years, but the last time I looked at some code involving Connector/Net was when I took the MySQL 5 Developer exam, which was long ago.
I'm using Linux on both my laptop and on servers for most projects. So I don't use or see many .NET code.
So I need a short refresh.
To use Connector/Net on Linux you will need to install Mono. The base for .NET is CIL, which exists in at least 4 versions: 1.0, 2.0 and 4.0. To compile C# code with mono you need the command which correspondends with the CIL version you are using.
- CIL 1.0: mcs
- CIL 2.0: gmcs
- CIL 4.0: dmcs
dmcs -r:System.Data.dll $(pkg-config --libs mysql-connector-net) example1.cs
And run it:
The Connector/Net Tutorial Intro on mysql.com has some example code.
I wrote some very very basic C# code based on the tutorial:
$ mono example1.exe
Connecting to MySQL...
public class Example1
public static void Main(string args)
string connStr = "server=localhost;user=msandbox;database=test;port=5612;password=msandbox";
MySqlConnection conn = new MySqlConnection(connStr);
Console.WriteLine("Connecting to MySQL...");
string sql = "SELECT VERSION()";
MySqlCommand cmd = new MySqlCommand(sql, conn);
MySqlDataReader rdr = cmd.ExecuteReader();
catch (Exception ex)