嘿,夥計們我正在使用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