我有一个 Windows CE 设备。我正在尝试运行使用 SqlServerCe 的应用程序。当我尝试运行ExecuteReader.Read()
方法时,它会引发如下异常:
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()
Sql 的其他方法不会导致问题(如 ExecuteNonQuery)。
我在该设备上有 Microsoft SQL Server Compact Edition\v3.5 和 .NET Framework 3.5。
我正在使用 VS 2008 智能设备应用程序进行开发。
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());
}
}
这就是发生期望的函数。