“用于Windows Phone的C#SQLite”;内存不足”;错误

本文关键字:内存不足 错误 C#SQLite 用于 Windows Phone | 更新日期: 2023-09-27 18:27:31

我一直在为Windows Phone使用SQLite(http://wp7sqlite.codeplex.com/)试图对我制作的两个表执行SELECT。当我尝试这样做时,当我调用cmd.ExecuteReader()时,我得到了一个"内存不足"的异常。

这是代码WP7/C#代码:

SqliteConnection conexion = new SqliteConnection("Version=3,uri=file:Database.db");
SqliteCommand sql = conexion.CreateCommand();
sql.CommandText = "SELECT a, b FROM tableA, tableB where tableA.id=tableB.id";
SqliteDataReader res = sql.ExecuteReader();

一旦执行ExecuteReader,就会显示"内存不足异常"。这是堆栈跟踪:

Message=out of memory
StackTrace:
at Community.CsharpSqlite.SQLiteClient.SqliteCommand.GetNextStatement(String pzStart, String& pzTail, Vdbe& pStmt)
at Community.CsharpSqlite.SQLiteClient.SqliteCommand.ExecuteReader(CommandBehavior behavior, Boolean want_results, Int32& rows_affected)
at Community.CsharpSqlite.SQLiteClient.SqliteCommand.ExecuteReader(CommandBehavior behavior)
at Community.CsharpSqlite.SQLiteClient.SqliteCommand.ExecuteReader()
at Carretera.Selector..ctor()
at System.Reflection.RuntimeConstructorInfo.InternalInvoke(RuntimeConstructorInfo rtci, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Activator.InternalCreateInstance(Type type, Boolean nonPublic, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type)
at System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(AsyncCallback userCallback, PageResourceContentLoaderAsyncResult result)
at System.Windows.Navigation.PageResourceContentLoader.<>c__DisplayClass4.<BeginLoad>b__0(Object args)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(RuntimeMethodInfo rtmi, Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean isBinderDefault, Assembly caller, Boolean verifyAccess, StackCrawlMark& stackMark)
at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, StackCrawlMark& stackMark)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Delegate.DynamicInvokeOne(Object[] args)
at System.MulticastDelegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.Dispatch(DispatcherPriority priority)
at System.Windows.Threading.Dispatcher.OnInvoke(Object context)
at System.Windows.Hosting.CallbackCookie.Invoke(Object[] args)
at System.Windows.Hosting.DelegateWrapper.InternalInvoke(Object[] args)
at System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(IntPtr pHandle, Int32 nParamCount, ScriptParam[] pParams, ScriptParam& pResult)

如有任何帮助,我们将不胜感激。

“用于Windows Phone的C#SQLite”;内存不足”;错误

我终于把它搞定了。对于任何需要解决方案的人,请重新检查数据库中是否存在列和/或数据库是否已正确创建。

我已经看到,当我使用事务创建数据库时,该数据库实际上并不存在。我认为事务失败了,我正在查询一个不存在的DB。我后来使用了独立存储资源管理器工具从模拟器下载了我创建的数据库,并对其进行了仔细检查。现在它工作正常了。

我不知道为什么SQLite显示"内存不足"错误,而实际上问题是不存在的文件本身。

希望这能帮助到和我有同样问题的人。