1

I have a Windows CE Device. I am trying to run an application which is using SqlServerCe. When I try to run ExecuteReader.Read() method it is throwing an exception like below:

Error
ExceptionCode: 0xc0000005
Exception Adress : 0x4d776569
Reading: 0x4d776568

at
NativeMethods.GetKeyInfo(IntPtrpTx,String pwszBase Table, IntPtrprgDbKeyInfo, Int 32 cDKeyInfo, IntPtr pError)
at
SqlCeDataReader.FillMetaData(SqlCeCommand command)
at
SqlCeCommand.InitializeDataReader(SqlCeDataReader reader, Int32 resultType)
at
SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResulSetOptions options)
at
SqlCeCommand.ExecuteReader(CommandBehavior behavior)
at
Prothocol.checkReadACK(SerialPort serialport,SqlCeCommand sql_cmd)
at
Message.communicationThread()

The other methods of Sql doesn't cause a problem (Like ExecuteNonQuery).

I have Microsoft SQL Server Compact Edition\v3.5 and .NET Framework 3.5 on that device.

And I am using VS 2008 Smart Device Application for developing.

 public static void checkReadACK(SerialPort serialport, SqlCeCommand sql_cmd)
        {
            String s;
            long selectedID;
            s = "SELECT receivedNum,id from MESSAGE_INBOX where (status = 2)"; //Status: 0 read and replied. 1 unread. 2 read and notreplied.
            try
            {
                sql_cmd.CommandText = s;
                sql_cmd.ExecuteNonQuery();
                SqlCeDataReader reader = sql_cmd.ExecuteReader();


                while (reader.Read())
                {
                    sendReadACK(reader.GetString(0),serialport);
                    selectedID = reader.GetInt64(1);
                    s = "UPDATE MESSAGE_INBOX SET status = 0 WHERE (id = " + selectedID + ")";
                    sql_cmd.CommandText = s;
                    sql_cmd.ExecuteNonQuery();
                }
            }
            catch //(Exception err)
            {
                //  MessageBox.Show(err.Message.ToString());
            }
        }

And this is the function where expection occurs.

  • 0xc0000005 normally denotes an access violation. Can you post your code? – Phil Murray Dec 20 '12 at 09:45
  • Have a look at [http://social.msdn.microsoft.com/Forums/sa/sqlce/thread/0a2a79ba-9b24-4192-a290-028e1472482f](this) and [(http://social.msdn.microsoft.com/Forums/hu-HU/netfxcompact/thread/421075ef-3bc8-4e0a-9439-2a54c27612e6](this) – Phil Murray Dec 20 '12 at 09:57
  • I have edit my post with the code part – Oguzkan Akbel Dec 20 '12 at 09:58
  • 1
    The only time I have had this in the past is when I have a version mismatch of the SQLCE dll's in my different projects. One had 3.5 while the other had 3.5 SP1. Can you check that. Also have a look at this link - http://blogs.msdn.com/b/sqlservercompact/archive/2009/05/06/troubleshooting-access-violation-exception-while-using-sql-server-compact-database-with-ado-net-provider.aspx – Phil Murray Dec 20 '12 at 10:39
  • Can you also check the return value from the ExecuteNonQuery() method. int result = sql_cmd.ExecuteNonQuery(); – Phil Murray Dec 20 '12 at 10:43
  • One last thing. Is this code called multiple times? You don't appear to be closing the SqlCeDataReader. If the code works the first time around but generates an exception on the second pass then that is probably the issue. Make sure you clean up your resources. – Phil Murray Dec 20 '12 at 10:53
  • I'm with @Phil - it's probably a version mismatch. I've seen it before as well. – ctacke Dec 20 '12 at 13:02

0 Answers0