I have C # code that cycles through .sql files and does what creates a database inside them.
A single .sql file basically looks like this:
DROP PROCEDURE IF EXISTS myProc; DELIMITER $$ CREATE PROCEDURE myProc() BEGIN
When I enter this into the MySQL Query Browser script window, it works fine ... again and again, as I would like.
However, if I put the line in my IDbCommand and executed it ...
connection.Open(); // An IDbConnection IDbTransaction transaction = connection.BeginTransaction(); using (IDbCommand cmd = connection.CreateCommand()) { cmd.Connection = connection; cmd.Transaction = transaction; cmd.CommandText = line; cmd.CommandType = CommandType.Text; try { cmd.ExecuteNonQuery(); } catch (SqlException ex) { transaction.Rollback(); return false; } } transaction.Commit(); connection.Close();
... I get the terrible exception 1064 ...
You have an error in the SQL syntax; check the manual that matches your version of MySQL server for the correct syntax to use near 'DELIMITER $$ CREATION PROCEDURE myProc () START ...
So the question is, why does MySQL allow me to do this without problems, but when I try to start it with C # it fails? And, of course, the second question is how I should fix it.
Brillyints
source share