Executing sql file with multiple statements

I want to execute a bunch of sql files and I am having file problems (I think) that have multiple statements in them. See here:

http://pastebin.com/yenknuq6

Trying to execute this sql throws this exception:

"at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader (CommandBehavior behavior) at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery ()"

I am using MySql connectors and I am not making any changes to the lines and just reading them from the file.

using (MySqlConnection conn = new MySqlConnection())
{
    try
    {
        conn.ConnectionString = connect_str;
        conn.Open();
        Console.WriteLine("\n[EXECUTING] " + file);
        String sql = File.ReadAllText(file);
        if (sql != null && !sql.Equals(""))
        {
            Debug.WriteLine(sql);
            MySqlCommand command = new MySqlCommand(sql, conn);
            command.CommandText = sql;
            command.Prepare();

            command.ExecuteNonQuery();
        }
        else
            Console.WriteLine("no sql");

        conn.Close();
    }
    catch (Exception e)
    {
        Console.WriteLine("[SQL EXCEPTION] " + e.StackTrace);
    }
}

      

+3


source to share


1 answer


You must enter the connection parameter Allow User Variables = True to get it to work.



0


source







All Articles