Fatal error encountered during command execut一句sql 在mysql上执行没问题,但是用.net连接执行时抛异常

时间:2022-03-11 18:31:54

select ret.amount,
       T.clubname,
       ret.lvl,
       @rank := @rank + 1 AS rank,
       (select ServerIndex from gameparameter) as serverindex
  from (SELECT SUM(COUNT) AS amount, clubid, lvl
          FROM (SELECT COUNT, clubid, CreateTime, Lvl
                  FROM coinfinanceback
                 WHERE Category = 1
                   and CreateTime >= ''
                   and CreateTime <= ''
                UNION ALLl 
                SELECT COUNT, clubid, CreateTime, Lvl
                  FROM coinfinance
                 WHERE Category = 1
                   and CreateTime >= ''
                   and CreateTime <= '') a
        
         GROUP BY clubid
         ORDER BY SUM(COUNT) DESC) ret
  left join clubinfo T
    on ret.clubid = t.clubid,(SELECT @rank   := 0) V


/* 0 rows affected, 2,158 rows found. Duration for 1 query: 0.297 sec. (+ 0.015 sec. network) */
请各位大牛帮分析下

7 个解决方案

#1


@rank通过Commnd的Parameters传参吧

#2


什么异常,说明白,是不是内置参数不匹配等平台问题

#3


mysql的sql参数化在.net中  @不是用?来代替的吗

#4


引用 2 楼 bdmh 的回复:
什么异常,说明白,是不是内置参数不匹配等平台问题

Fatal error encountered during command execution.
   在 MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   在 MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   在 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
   在 Helper.MySQLHelper.ExecuteDataset(MySqlConnection connection, CommandType commandType, String commandText, MySqlParameter[] commandParameters) 位置 D:\Prj\XDLQ2012\Helper\MySQLHelper.cs:行号 232
   在 Helper.MySQLHelper.ExecuteDataSet(String strCon, CommandType commandType, String commandText, MySqlParameter[] commandParameters) 位置 D:\Prj\XDLQ2012\Helper\MySQLHelper.cs:行号 213
   在 Helper.MySQLHelper.ExecuteDataTable(String strCon, CommandType commandType, String commandText, MySqlParameter[] commandParameters) 位置 D:\Prj\XDLQ2012\Helper\MySQLHelper.cs:行号 190
   在 XDLQManager.DAL.CoinFinance.GetConsumRank(String serverConn, DateTime begin, DateTime end) 位置 D:\Prj\XDLQ2012\XDLQManager.DAL\CoinFinance.cs:行号 228
   在 XDLQBackendServices.Pages.ConsumptionRank.GetGiftCenterRecords(String begin, String end) 位置 D:\Prj\XDLQ2012\XDLQBackendServices\Pages\ConsumptionRank.aspx.cs:行号 84
   在 XDLQBackendServices.Pages.ConsumptionRank.Process_SearchClick() 位置 D:\Prj\XDLQ2012\XDLQBackendServices\Pages\ConsumptionRank.aspx.cs:行号 68
   在 XDLQBackendServices.Pages.BasePage.BasePage.ExecuteEventProxy(Delegate eventProxy, Object sender, EventArgs e) 位置 D:\Prj\XDLQ2012\XDLQBackendServices\Pages\BasePage\BasePage.cs:行号 61

#5


就是参数的问题
MySqlParameter

#6


引用 3 楼 yyl8781697 的回复:
mysql的sql参数化在.net中  @不是用?来代替的吗

select ret.amount,
                           T.clubname,
                           ret.lvl,
                           @rank := @rank + 1 AS rank,
                           (select ServerIndex from gameparameter) as serverindex
                              from (SELECT SUM(COUNT) AS amount, clubid, lvl
                                      FROM (SELECT COUNT, clubid, CreateTime, Lvl
                                              FROM coinfinanceback
                                             WHERE Category = 1
                                               and CreateTime >= ?begin
                                               and CreateTime <= ?end
                                            UNION ALL
                                            SELECT COUNT, clubid, CreateTime, Lvl
                                              FROM coinfinance
                                             WHERE Category = 1
                                               and CreateTime >= ?begin
                                               and CreateTime <= ?end) a        
                                     GROUP BY clubid
                                     ORDER BY SUM(COUNT) DESC) ret
                              left join clubinfo T
                                on ret.clubid = t.clubid ,(SELECT @rank   := 0) V
 那两个时间是参数化的变量 .... @的不是

#7


Fatal error encountered during command execut一句sql 在mysql上执行没问题,但是用.net连接执行时抛异常


引用 5 楼 gxingmin 的回复:
就是参数的问题
MySqlParameter

#1


@rank通过Commnd的Parameters传参吧

#2


什么异常,说明白,是不是内置参数不匹配等平台问题

#3


mysql的sql参数化在.net中  @不是用?来代替的吗

#4


引用 2 楼 bdmh 的回复:
什么异常,说明白,是不是内置参数不匹配等平台问题

Fatal error encountered during command execution.
   在 MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   在 MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   在 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   在 System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
   在 Helper.MySQLHelper.ExecuteDataset(MySqlConnection connection, CommandType commandType, String commandText, MySqlParameter[] commandParameters) 位置 D:\Prj\XDLQ2012\Helper\MySQLHelper.cs:行号 232
   在 Helper.MySQLHelper.ExecuteDataSet(String strCon, CommandType commandType, String commandText, MySqlParameter[] commandParameters) 位置 D:\Prj\XDLQ2012\Helper\MySQLHelper.cs:行号 213
   在 Helper.MySQLHelper.ExecuteDataTable(String strCon, CommandType commandType, String commandText, MySqlParameter[] commandParameters) 位置 D:\Prj\XDLQ2012\Helper\MySQLHelper.cs:行号 190
   在 XDLQManager.DAL.CoinFinance.GetConsumRank(String serverConn, DateTime begin, DateTime end) 位置 D:\Prj\XDLQ2012\XDLQManager.DAL\CoinFinance.cs:行号 228
   在 XDLQBackendServices.Pages.ConsumptionRank.GetGiftCenterRecords(String begin, String end) 位置 D:\Prj\XDLQ2012\XDLQBackendServices\Pages\ConsumptionRank.aspx.cs:行号 84
   在 XDLQBackendServices.Pages.ConsumptionRank.Process_SearchClick() 位置 D:\Prj\XDLQ2012\XDLQBackendServices\Pages\ConsumptionRank.aspx.cs:行号 68
   在 XDLQBackendServices.Pages.BasePage.BasePage.ExecuteEventProxy(Delegate eventProxy, Object sender, EventArgs e) 位置 D:\Prj\XDLQ2012\XDLQBackendServices\Pages\BasePage\BasePage.cs:行号 61

#5


就是参数的问题
MySqlParameter

#6


引用 3 楼 yyl8781697 的回复:
mysql的sql参数化在.net中  @不是用?来代替的吗

select ret.amount,
                           T.clubname,
                           ret.lvl,
                           @rank := @rank + 1 AS rank,
                           (select ServerIndex from gameparameter) as serverindex
                              from (SELECT SUM(COUNT) AS amount, clubid, lvl
                                      FROM (SELECT COUNT, clubid, CreateTime, Lvl
                                              FROM coinfinanceback
                                             WHERE Category = 1
                                               and CreateTime >= ?begin
                                               and CreateTime <= ?end
                                            UNION ALL
                                            SELECT COUNT, clubid, CreateTime, Lvl
                                              FROM coinfinance
                                             WHERE Category = 1
                                               and CreateTime >= ?begin
                                               and CreateTime <= ?end) a        
                                     GROUP BY clubid
                                     ORDER BY SUM(COUNT) DESC) ret
                              left join clubinfo T
                                on ret.clubid = t.clubid ,(SELECT @rank   := 0) V
 那两个时间是参数化的变量 .... @的不是

#7


Fatal error encountered during command execut一句sql 在mysql上执行没问题,但是用.net连接执行时抛异常


引用 5 楼 gxingmin 的回复:
就是参数的问题
MySqlParameter