My code structure to create a new Access database is in this order:
1. Create the database
2. Open the database
3. Create a database table
Is this the same order that I should apply for creating a mySQL database?
It's not quite the same; Access is a file-based database system, where MySQL is server-based, so you'll need some sort of open connection to the server to do anything useful.
When the program attempts to run the ExecuteNonQuery command for CREATE DATABASE, it fails because it requires an open database connection (ExecuteNonQuery requires an open and available Connection. The connection's current state is closed.)
I don't have a server handy to test this on, and I'm not sure what MySQL library you're using (
ODBC,
Connector/Net?)... but I
think it would look something like this:
MySqlConnection connection = new MySqlConnection("Data Source=serverName;UserId=rootOrOtherAdminAccount;PWD=topSecretPassword;");
MySqlCommand command = new MySqlCommand("CREATE DATABASE FancyDatabase;", connection);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
Is that different than what your code is doing?