我有C#代码循环.sql文件并执行其中的内容来设置数据库.
DROP PROCEDURE IF EXISTS myProc; DELIMITER $$ CREATE PROCEDURE myProc() BEGIN -- procedure stuff goes here END $$ DELIMITER ; CALL myProc();
当我将它输入到MySQL查询浏览器的脚本窗口时,它会一遍又一遍地运行,就像人们希望的那样.
但是,如果我将字符串放入我的IDbCommand并执行它…
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();
……我得到了可怕的例外1064 ……
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 ‘DELIMITER $$CREATE PROCEDURE myProc() BEGIN…
所以,问题是……为什么MysqL让我这样做没有问题,但是当我尝试从C#运行它时,它失败了?当然第二个问题是我应该如何修复它.