在 Monodroid 上部署时丢失 Sqlite 表 [英] Losing Sqlite tables when deploying to on Monodroid

查看:21
本文介绍了在 Monodroid 上部署时丢失 Sqlite 表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用的是 Visual Studio 2010、Monodroid 和 SQLite

We are using Visual Studio 2010, Monodroid and SQLite

我们使用 SqliteConnection.CreateFile(...) 方法在路径 myContext.GetDatabasePath("mydb.db3").AbsolutePath 创建一个数据库.

We create a database at path myContext.GetDatabasePath("mydb.db3").AbsolutePath using the SqliteConnection.CreateFile(...) method.

所以我们的连接字符串是Data Source=/data/data/myapp.myapplication/databases/mydb.db3temp;"

So our connection string is "Data Source=/data/data/myapp.myapplication/databases/mydb.db3temp;"

我们创建一个表并使用 SqliteCommand.ExecuteNonQuery() 插入多条记录.

We create a table and insert several records using SqliteCommand.ExecuteNonQuery().

我们可以在插入后立即使用 SqliteCommand.ExecuteScalar() 运行选择查询.

We can run select queries with SqliteCommand.ExecuteScalar() immediately after inserting.

SqliteDataAdapter.Fill(table) 方法没有成功运行并给我们这个异常:

SqliteDataAdapter.Fill(table) method does not run successfully and gives us this exception:

System.EntryPointNotFoundException: sqlite3_column_origin_name
 at (wrapper managed-to-native) Mono.Data.Sqlite.UnsafeNativeMethods:sqlite3_column_origin_name (intptr,int)
 at Mono.Data.Sqlite.SQLite3.ColumnOriginalName (Mono.Data.Sqlite.SqliteStatement stmt, Int32 index) [0x00000] in <filename unknown>:0 
 at Mono.Data.Sqlite.SqliteDataReader.GetSchemaTable (Boolean wantUniqueInfo, Boolean wantDefaultValue) [0x00000] in <filename unknown>:0 
 at Mono.Data.Sqlite.SqliteDataReader.GetSchemaTable () [0x00000] in <filename unknown>:0 
 at System.Data.Common.DataAdapter.BuildSchema (IDataReader reader, System.Data.DataTable table, SchemaType schemaType, MissingSchemaAction missingSchAction, MissingMappingAction missingMapAction, System.Data.Common.DataTableMappingCollection dtMapping) [0x00000] in <filename unknown>:0 
 at System.Data.Common.DataAdapter.BuildSchema (IDataReader reader, System.Data.DataTable table, SchemaType schemaType) [0x00000] in <filename unknown>:0 
 at System.Data.Common.DataAdapter.FillTable (System.Data.DataTable dataTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords, System.Int32& counter) [0x00000] in <filename unknown>:0 
 at System.Data.Common.DataAdapter.FillInternal (System.Data.DataTable dataTable, IDataReader dataReader) [0x00000] in <filename unknown>:0 
 at System.Data.Common.DataAdapter.Fill (System.Data.DataTable dataTable, IDataReader dataReader) [0x00000] in <filename unknown>:0 
 at System.Data.Common.DbDataAdapter.Fill (System.Data.DataTable dataTable, IDbCommand command, CommandBehavior behavior) [0x00000] in <filename unknown>:0 
 at System.Data.Common.DbDataAdapter.Fill (System.Data.DataTable dataTable) [0x00000] in <filename unknown>:0 
 at (wrapper remoting-invoke-with-check) System.Data.Common.DbDataAdapter:Fill (System.Data.DataTable)
 at ...

如果我们对应用程序代码进行任何更改并重新部署,那么 db 文件仍然存在于 android 设备上,但 SqliteCommand.ExecuteScalar() 和 SqliteDataAdapter.Fill(table) 将抛出异常,表示该表不存在:

If we make any changes to the application code and redeploy, then the db file still exists on the android device but SqliteCommand.ExecuteScalar() and SqliteDataAdapter.Fill(table) will throw exceptions that say that the table does not exist:

Mono.Data.Sqlite.SqliteException: SQLite error
no such table: MyTable
 at Mono.Data.Sqlite.SQLite3.Prepare (Mono.Data.Sqlite.SqliteConnection cnn, System.String strSql, Mono.Data.Sqlite.SqliteStatement previous, UInt32 timeoutMS, System.String& strRemain) [0x00000] in <filename unknown>:0 
 at Mono.Data.Sqlite.SqliteCommand.BuildNextCommand () [0x00000] in <filename unknown>:0  

这是预期的 Monodroid 行为吗?重新部署应用程序后我们应该丢失表吗?我们应该如何使用SqliteDataAdapter.Fill()?

Is this expected Monodroid behavior? Should we lose the tables after re-deploying the application? How should we use SqliteDataAdapter.Fill()?

谢谢

推荐答案

默认情况下,当您在 Android 上卸载应用程序时,您创建的文件会被删除.在 Visual Studio 中,转到 Tools->Options->Mono for Android 并打开在应用程序部署之间保留数据".这将传递一个卸载标志,告诉它在设备上保留您的数据.

By default, files you create get deleted when you uninstall the app on Android. In Visual Studio, go to Tools->Options->Mono for Android and turn on "Preserve data between application deploys". This will pass a flag to uninstall that tells it to leave your data on the device.

这篇关于在 Monodroid 上部署时丢失 Sqlite 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆