如何在 Xamarin UWP 中访问 Sqlite 数据库文件 [英] How to access Sqlite database file in Xamarin UWP

查看:41
本文介绍了如何在 Xamarin UWP 中访问 Sqlite 数据库文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Xamarin 项目.在我的 UWP 项目的根目录中,我存储了一个 sqlite 文件,其中包含我的应用程序需要的初始表.我将构建操作"设置为内容".我发现的所有示例都在ApplicationData.Current.LocalFolder.Path"中查找该文件,但是当我运行该应用程序时,该文件夹中没有任何内容.一切都在 Debug 文件夹中创建.我应该使用不同的路径进行调试和发布吗?存储如何工作?应用是否在 UWP 中被沙盒化?

I have a Xamarin project. In my UWP project's root, I stored a sqlite file that has initial tables my app needs. I set the 'Build Action' to 'Content'. All examples I found look for the file in 'ApplicationData.Current.LocalFolder.Path', but when I run the app, there is nothing in that folder. Everything gets created in Debug folder. Should I use a different path for debug and release? How does the storage work? Are apps being sandboxed in UWP?

推荐答案

我找到的所有示例都在ApplicationData.Current.LocalFolder.Path"中查找该文件,但是当我运行该应用程序时,该文件夹中没有任何内容

All examples I found look for the file in 'ApplicationData.Current.LocalFolder.Path', but when I run the app, there is nothing in that folder

是的,您设置的sqlite文件只是UWP应用的一个Content,我们需要在第一次运行时以编程方式将其复制到LocalFolder.使用 StorageFile.CopyAsync() 复制文件到指定位置的方法

Yes, the sqlite file you have set is just a Content for the UWP app, we need to copy it to LocalFolder programmatically in the first run. Using StorageFile.CopyAsync() method to copy file to the specific location

请参阅 Sunteen 在此 问题

另一个位置是可以读/写的应用程序数据位置.您可以将数据库文件从安装目录复制到应用程序数据目录中使用.以下代码示例用于连接本地文件夹中的数据库文件......

Another location is Application data locations which can read/write. You can copy the database file from install directory to the application data directory for using. The following code example is for connecting a database file that in the local folder......

这篇关于如何在 Xamarin UWP 中访问 Sqlite 数据库文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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