一、情形:
在.net調用Mysql時,比如如下的一句SQL,總是無法執行,可是在其它SQL客戶端窗口中是能正確執行的。
drop procedure if exists AddColumnUnlessExists; create procedure AddColumnUnlessExists(IN tableName tinytext,IN fieldName tinytext,IN fieldDef text) begin IF NOT EXISTS( SELECT * FROM information_schema.COLUMNS WHERE column_name = fieldName and table_name = tableName and table_schema = 'MyTestDB' ) THEN set @ddl = CONCAT('ALTER TABLE ', 'MyTestDB', '.', tableName,' ADD COLUMN ', fieldName, ' ', fieldDef); prepare stmt from @ddl; execute stmt; END IF; end; "
二、解決方案:
連接語句中添加:allowuservariables=True;即可。