Creating a database using Connector/NET Programming?

You need to execute the command and also make sure to properly dispose objects:

string connStr = "server=localhost;user=root;port=3306;password=mysql;";
using (var conn = new MySqlConnection(connStr))
using (var cmd = conn.CreateCommand())
{
    conn.Open();
    cmd.CommandText = "CREATE DATABASE IF NOT EXISTS `hello`;";
    cmd.ExecuteNonQuery();
}

You might want to execute the MySqlCommand. Now you just create one, but it doesn't execute your query.

Try this:

conn.Open();
s0 = "CREATE DATABASE IF NOT EXISTS `hello`;";
cmd = new MySqlCommand(s0, conn);
cmd.ExecuteNonQuery();
conn.Close();

Tags:

C#

Mysql

Database