Fatal error encountered during command execution.
sql语句如下图,HeidiSQL执行语句成功,在C#中执行语句一直报错,经验证是因为使用了变量。
SELECT Id,BeginTime,EndTime,DeviceState,StateCategory,Remark,@rownum:=@rownum + 1 AS Num
FROM SysDeviceState,(
SELECT @rownum:=0)t
WHERE 1=1 AND StateDate='2021-06-10'
ORDER BY BeginTime ASC
修改方法:在conn连接字符串中添加Allow User Variables=True
<connectionStrings>
<add name="MySqlConn" providerName="MySql.Data.MySqlClient" connectionString="Data Source=localhost;Initial Catalog=xxxxxx;Persist Security Info=True;user id=xxxx;password=xxxxxxxx;Charset=utf8;Allow User Variables=True"/>
</connectionStrings>