I am getting following exception with my code
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''MachineSimulator''
var sqlParams = new[]
{
new MySqlParameter("@MachineSimulatorDb",GlobalVariables.MachineSimulatorDb),
new MySqlParameter("@CAMXMassagesTable" ,GlobalVariables.CamxmassagesTable)
};
using (var conn = new MySqlConnection(GlobalVariables.ConnectionString))
{
conn.Open();
using(var command = new MySqlCommand())
{
command.Connection = conn;
command.Parameters.AddRange(sqlParams);
command.CommandText = "CREATE DATABASE IF NOT EXISTS @MachineSimulatorDb;";
command.ExecuteNonQuery();
}
}
Any idea what is wrong there ?
Thanks
MySQL probably doesn’t allow you to pass a parameter to
create database. Try:If the variables you use come from an usafe source, you should be aware of the danger of SQL Injection.