我在使用ExecuteNonQuery()时遇到致命错误。
我是新来的使用SQL,因此我不知道为什么这个SET命令导致问题。
我使用MySql 5.5.17,并且在VS2010 IDE中使用C#.Net Framework 3.5。
异常消息=执行命令期间遇到致命错误。
错误行= SET @oldguid = 250006;
来自sql文件即时通讯使用的内容如下减去我删除的“评论”:
DELETE FROM `disables` WHERE `sourceType`=0 AND `entry`=61904;
INSERT INTO `disables` (`sourceType`, `entry`, `flags`, `comment`) VALUES(0, 61904, 8, 'Magma Totem TEST - can crash client by spawning too many totems');
SET @oldguid = 250006;
SET @newguid = 202602;
UPDATE `creature` SET `guid`=@newguid WHERE `guid`=@oldguid;
UPDATE `creature_addon` SET `guid`=@newguid, `path_id`=@newguid*100 WHERE `guid`=@oldguid;
UPDATE `waypoint_data` SET `id`=@newguid*100 WHERE `id`=@oldguid*100;
UPDATE `areatrigger_teleport` SET `target_orientation`=2.255664 WHERE `id`=4386;
UPDATE `gameobject` SET `spawnMask`=3 WHERE `guid`=22674;guid列是一个无符号整型(10)
我用来处理这个.sql文件的C#代码如下:
filename = lstBox_SqlFiles.SelectedItem.ToString();
mysql = new MySqlConnection(connection + Database);
string line;
OpenDatabase();
using (StreamReader reader = new StreamReader(filename))
{
StringBuilder parsedLine = new StringBuilder();
int count = 0;
while ((line = reader.ReadLine()) != null)
{
if (line.Length > 0 && !line.StartsWith("--"))
{
if (line.EndsWith(";"))
{
if (parsedLine.Length > 0)
line = parsedLine.ToString() + line;
try
{
count++;
lbl_LineQuery.Text = line;
lbl_QueryCount.Text = String.Format("Count: {0}", count);
MySqlCommand cmd = new MySqlCommand(line, mysql);
cmd.ExecuteNonQuery();
}
catch (MySqlException ex)
{
string msg = String.Format("Source FileName: SqlUpdater.cs\nSql FileName: {0}\nError Line: {1}\nException Message: {2}\n", filename, line, ex.Message);
MessageBox.Show("cmd.ExecuteNonQuery() Error!\n" + msg, "MySql Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
return;
}
sbClear(parsedLine);
}
else
{
parsedLine.Append(line);
continue;
}
}
else
continue;
}
}任何人都可以看到我的代码有问题吗?是否需要对“SET @var”字符串进行特殊操作?
任何帮助表示赞赏
提前致谢
路线大师
编辑*作为一个侧面说明,我应该指出,如果我使用SQL管理程序如SQLYog它处理相同的SQL文件没有问题,所以即时通讯假设问题是在我的C#代码中的字符串操纵的某个地方