嘿,伙计们我正在使用Windows Mobile 5.0(.Net 2.0) ,并且我陷入了一个小问题,我的阅读器始终为空。我的联系很好,我相信其他一切都很好,唯一的问题是读者。 在我的异常俘获它说SqlCeDataReader始终为空
((System.Data.SqlServerCe.SqlCeException)(e)) : {"The operation completed successfully."}
InnerException: Could not evaluate expression
我的数据库文件未损坏我打开它的应用程序之外,一切都看起来很好。 我的代码如下:
public static List<Image> GetAll(BOI caller)
{
List<Image> images = new List<Image>();
SqlCeConnection c = Connection.GetConnection(caller.ConnectionString);
if (c != null)
{
SqlCeCommand command = new SqlCeCommand("SELECT * FROM Images", c);
SqlCeDataReader reader = null;
try
{
reader = command.ExecuteReader(); <<<<< reader is null <<<<<<<
}
catch (Exception e)
{
while (reader != null && reader.Read())
{
Image temp = new Image((int)reader["imageKey"],
(String)reader["filename"],
(byte[])reader["image"],
(reader["labelKey"] == DBNull.Value ? null : (int?)reader["labelKey"]),
(int)reader["priority"]);
temp.SetDBName(caller.ConnectionString);
images.Add(temp);
}
}
}
return images;
}
编辑 我打开我的Connection.GetConnection连接(..);
编辑:2 的e.StackTrace:
at System.Data.SqlServerCe.SqlCeDataReader.ProcessResults(Int32 hr)
at System.Data.SqlServerCe.SqlCeDataReader.FillMetaData(SqlCeCommand command)
at System.Data.SqlServerCe.SqlCeCommand.InitializeDataReader(SqlCeDataReader reader, Int32 resultType)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SqlServerCe.SqlCeCommand.ExecuteReader()
at Oralys.BOI.DataAccess.ImageMapper.GetAll(BOI caller)
at Oralys.BOI.BOI.get_Images()
at Oralys.BOI.BOI_Controller.FetchAllImages()
at IdeoVoiceMobile.RunProfile.InitBOI()
at IdeoVoiceMobile.RunProfile..ctor()
at IdeoVoiceMobile.Program.startProfile()
at IdeoVoiceMobile.Program.Main()
获取连接函数:
public static SqlCeConnection GetConnection(string connectionString)
{
SqlCeConnection conn = null;
try
{
if (connections.Count == 0)
{
OpenConnection(connectionString);
}
conn = connections[connectionString];
}
catch (System.Exception)
{
}
return conn;
}
编辑:3 异常代码使用时
SqlCeCommand command = new SqlCeCommand("SELECT * FROM Images Where imageKey=6", c);
ExceptionCode: 0xc0000005
ExceptionAddress: 0x0115438c
Reading: 0x00000000
Faulting module: sqlceqp35.dll
Offset: 0x0001438c
at NativeMethods.GetKeyInfo(IntPtr pIUnknown, IntPtr pTx, String pwszBaseTable, IntPtr prgDbKeyInfo, Int32 cDbKeyInfo, IntPtr pError)
at SqlCeDataReader.FillMetaData(SqlCeCommand command)
at SqlCeCommand.InitializeDataReader(SqlCeDataReader reader, Int32 resultType)
at SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)
at SqlCeCommand.ExecuteReader(CommandBehavior behavior)
at SqlCeCommand.ExecuteReader()
at ImageMapper.GetAll(BOI caller)
at BOI.get_Images()
at BOI_Controller.FetchAllImages()
at RunProfile.InitBOI()
at RunProfile..ctor()
at Program.startProfile()
at Program.Main()
显示接下来的几行代码会有帮助 – 2012-03-05 16:06:34
我看不到你明确地打开连接?这是在'GetConnection'中吗? – rrrr 2012-03-05 16:08:19
是要编辑我的问题写这个。 – raym0nd 2012-03-05 16:08:47