C#SQLite for Windows Phone“内存不足”错误

时间:2012-03-12 03:15:30

标签: c# sqlite windows-phone-7.1 windows-phone

我一直在使用SQLite for Windows Phone(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)

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:2)

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

我看到当我使用事务创建数据库时,该数据库实际上并不存在。我认为交易失败了,我正在查询不存在的数据库。我以后使用了Isolated Storage Explorer工具从模拟器下载我创建的数据库并仔细检查它。现在它的工作正常。

我不知道为什么当实际问题是不存在的文件本身时,SQLite会显示“内存不足”错误。

希望这可以帮助与我有同样问题的人。