0

我在 win7 x64 平台上使用 mysql .net 连接器 6.4.4。从 MySqlDataReader 对象读取数据时,它在第 18 行后抛出异常。但在另一个应用程序中,我可以无错误地取 40 行。

错误就在这里:

MySqlDataReader.Read()

任何帮助将不胜感激。

Exception details:

System.ArgumentOutOfRangeException was unhandled
  Message=Non-negative number required.
Parameter name: count
  Source=mscorlib
  ParamName=count
  StackTrace:
       at System.IO.MemoryStream.Read(Byte[] buffer, Int32 offset, Int32 count)
       at MySql.Data.MySqlClient.MySqlPacket.Read(Byte[] byteBuffer, Int32 offset, Int32 count)
       at MySql.Data.MySqlClient.MySqlPacket.ReadString(Int64 length)
       at MySql.Data.Types.MySqlString.MySql.Data.Types.IMySqlValue.ReadValue(MySqlPacket packet, Int64 length, Boolean nullVal)
       at MySql.Data.MySqlClient.NativeDriver.ReadColumnValue(Int32 index, MySqlField field, IMySqlValue valObject)
       at MySql.Data.MySqlClient.Driver.ReadColumnValue(Int32 index, MySqlField field, IMySqlValue value)
       at MySql.Data.MySqlClient.ResultSet.ReadColumnData(Boolean outputParms)
       at MySql.Data.MySqlClient.ResultSet.NextRow(CommandBehavior behavior)
       at MySql.Data.MySqlClient.MySqlDataReader.Read()
       at VeriTasima.Form1..ctor() in E:\Projeler\VeriTasima\VeriTasima\Form1.cs:line 42
       at VeriTasima.Program.Main() in E:\Projeler\VeriTasima\VeriTasima\Program.cs:line 18
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 

更新:

// test
            string commandString = "SELECT * FROM haber LIMIT 50";
            MySqlConnection connection = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MySQL"].ConnectionString);
            MySqlCommand command = new MySqlCommand(commandString, connection);
            connection.Open();
            MySqlDataReader sdr = command.ExecuteReader();
            int count = 0;
            while (sdr.Read())
            {
                count++;
            }
            sdr.Close();
            sdr.Dispose();
            command.Dispose();
            connection.Close();
            connection.Dispose();
            MessageBox.Show(count.ToString());

更新:

我通过将目标平台从 x86 设置为任何 CPU 来解决此问题。现在可以正常工作。

4

0 回答 0