只有从我的C#应用程序运行该过程时,我才收到错误MySql.Data.MySqlClient.MySqlException (0x80004005): Unknown column 'group' in 'field list'
。为了让我更加困惑,我的应用程序每次执行该过程都不会发生此错误,但有时也是如此。对于表中的相同数据,有时我得到错误,有时不会。当从某些MySql Management Studio运行该过程时,我从未遇到过这种错误。
这是程序:
PROCEDURE TestProcedure()
BEGIN
-- creating temporary table
CREATE TEMPORARY TABLE IF NOT EXISTS Duplicates_tmp (
field1 TEXT DEFAULT NULL,
field2 TEXT DEFAULT NULL
);
-- insert duplicates from keys in temp table (one row of every duplicates)
INSERT INTO Duplicates_tmp (field1, field2)
SELECT Field1, Field2
FROM keys
GROUP BY Field2
HAVING COUNT(*) > 1;
-- delete all duplicates from table Key
DELETE from keys where Field2 IN (SELECT field2 from Duplicates_tmp);
-- insert one row of every duplicates found
INSERT INTO keys (Field1, Field2)
SELECT field1, field2
FROM Duplicates_tmp;
END
使用此C#代码调用该过程:
MySqlConnection mysql_con = new MySqlConnection();
mysql_con = new MySqlConnection(connection_string);
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
cmd.Connection = mysql_con;
cmd.CommandText = "CALL TestProcedure";
mysql_con.Open();
cmd.CommandTimeout = 120000;
cmd.ExecuteNonQuery();
mysql_con.Close();