Open extern SQLite-Database in a Windows 8 Metro-App?

大城市里の小女人 提交于 2019-12-12 03:43:22

问题


I use the "Sqlite for Windows Runtime" and sqlite-net (just as described at http://timheuer.com/blog/archive/2012/08/07/updated-how-to-using-sqlite-from-windows-store-apps.aspx) to develop a Windows 8 Metro-App, just . If I want to open a Database at the Program-Directory is no problem:

var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "db.sqlite");
using (var db = new SQLite.SQLiteConnection(dbPath)) {
  ...
}

But when I want to use an extern Path like this:

var dbPath = "C:\\Users\\xxxxxx\\db.sqlite";

then an error occurs with "Cannot open database file". Why? Here I am using C#, normally I use C++, but for this problem I am sure it doesn't matter ;)


回答1:


You cannot select arbitrary files on the file system. See here for details.

By default you can access these locations:

  • Application install directory
  • Application data locations
  • User’s Downloads folder

and

Additionally, your app can access some of the files on connected devices by default. This is an option if your app uses the AutoPlay Device extension to launch automatically when users connect a device, like a camera or USB thumb drive, to their system. The files your app can access are limited to specific file types that are specified via File Type Association declarations in your app manifest. Of course, you can also gain access to files and folders on a removable device by calling the file picker (using FileOpenPicker and FolderPicker) and letting the user pick files and folders for your app to access. Learn how to use the file picker in Quickstart: Accessing files with file pickers.

If you have the right capabilities declared you can also access:

  • Documents Library
  • Music Library
  • Picture Library
  • Videos Library
  • Homegroup Library
  • Removable devices
  • Media server devices (DLNA)
  • Universal Naming Convention (UNC) folders

A combination of the following capabilities is needed. The home and work networks capability:

PrivateNetworkClientServer

And at least one internet and public networks capability:

InternetClient InternetClientServer

And, if applicable, the domain credentials capability:

EnterpriseAuthentication

Note You must add File Type Associations to your app manifest that declare specific file types that your app can access in this location.




回答2:


In windows metro application... It support only sandbox property of an application.

So you cant use

var dbPath = "C:\\Users\\xxxxxx\\db.sqlite";

U can only store data in local storage or application installed directory.

Please avoid to use any other path . it will not work .



来源:https://stackoverflow.com/questions/12220751/open-extern-sqlite-database-in-a-windows-8-metro-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!