Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 8 如何在windows 8 RT中保存和打开连接SQLite数据库文件(但应用程序临时文件夹除外)?_Windows 8_Sqlite_Microsoft Metro - Fatal编程技术网

Windows 8 如何在windows 8 RT中保存和打开连接SQLite数据库文件(但应用程序临时文件夹除外)?

Windows 8 如何在windows 8 RT中保存和打开连接SQLite数据库文件(但应用程序临时文件夹除外)?,windows-8,sqlite,microsoft-metro,Windows 8,Sqlite,Microsoft Metro,伙计们,现在我有一个问题,这真的让我想知道 我目前正在开发一个Windows 8 RT应用程序,应用程序存储数据到本地,因此我选择使用SQLite for WinRT(包括SQLite.cs SQLiteAsync.cs、SQLite3.dll),默认情况下,SQLite for WinRT将数据库文件存储在应用程序临时文件夹中 public SQLiteConnection (string databasePath, bool storeDateTimeAsTicks = false): th

伙计们,现在我有一个问题,这真的让我想知道

我目前正在开发一个Windows 8 RT应用程序,应用程序存储数据到本地,因此我选择使用SQLite for WinRT(包括SQLite.cs SQLiteAsync.cs、SQLite3.dll),默认情况下,SQLite for WinRT将数据库文件存储在应用程序临时文件夹中

public SQLiteConnection (string databasePath, bool storeDateTimeAsTicks = false): this (databasePath, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create, storeDateTimeAsTicks)
        {
        }

        /// <summary>
        /// Constructs a new SQLiteConnection and opens a SQLite database specified by databasePath.
        /// </summary>
        /// <param name="databasePath">
        /// Specifies the path to the database file.
        /// </param>
        /// <param name="storeDateTimeAsTicks">
        /// Specifies whether to store DateTime properties as ticks (true) or strings (false). You
        /// absolutely do want to store them as Ticks in all new projects. The default of false is
        /// only here for backwards compatibility. There is a *significant* speed advantage, with no
        /// down sides, when setting storeDateTimeAsTicks = true.
        /// </param>
        public SQLiteConnection (string databasePath, SQLiteOpenFlags openFlags, bool storeDateTimeAsTicks = false)
        {
            DatabasePath = databasePath;

#if NETFX_CORE
            SQLite3.SetDirectory(/*temp directory type*/2, Windows.Storage.ApplicationData.Current.TemporaryFolder.Path);
#endif

            Sqlite3DatabaseHandle handle;

#if SILVERLIGHT || USE_CSHARP_SQLITE
            var r = SQLite3.Open (databasePath, out handle, (int)openFlags, IntPtr.Zero);
#else
            // open using the byte[]
            // in the case where the path may include Unicode
            // force open to using UTF-8 using sqlite3_open_v2
            var databasePathAsBytes = GetNullTerminatedUtf8 (DatabasePath);
            var r = SQLite3.Open (databasePathAsBytes, out handle, (int) openFlags, IntPtr.Zero);
#endif

            Handle = handle;
            if (r != SQLite3.Result.OK) {
                throw SQLiteException.New (r, String.Format ("Could not open database file: {0} ({1})", DatabasePath, r));
            }
            _open = true;

            StoreDateTimeAsTicks = storeDateTimeAsTicks;

            BusyTimeout = TimeSpan.FromSeconds (0.1);
        }
但它对以下方面提出了异议:

var r = SQLite3.Open(databasePathAsBytes, out handle, (int)openFlags, IntPtr.Zero);

            Handle = handle;
            if (r != SQLite3.Result.OK)
            {
                throw SQLiteException.New(r, String.Format("Could not open database file: {0} ({1})", DatabasePath, r));
            }
它说不能打开文件。我想问题可能是'SQLite3.SetDirectory(/temp directory type/2,storeFloderPath)','2'是stand temp目录类型。这些没有官方文件,所以我尝试了从0到6的参数,它也不起作用,例外情况与原始情况相同

任何人都知道怎么做,或者我的代码中有错误。
提前谢谢

谢谢你的回答,我找到了一个病态的解决方法,当我想打开其他文件夹中的数据库连接时,首先将数据库文件复制到应用程序本地文件夹(Windows.Storage.ApplicationData.Current.LocalFolder),然后连接到数据库文件,然后成功


但是我希望SQLite for WinRT的开发人员能够注意到这个问题,并解决它

您是否指定访问应用程序清单中的documents文件夹?如果您确实这样做,特别是使用DocumentsLibrary,请知道您需要一个“公司”帐户来将这样的应用程序部署到应用商店,不仅仅是一个开发人员,是的,当然有
var r = SQLite3.Open(databasePathAsBytes, out handle, (int)openFlags, IntPtr.Zero);

            Handle = handle;
            if (r != SQLite3.Result.OK)
            {
                throw SQLiteException.New(r, String.Format("Could not open database file: {0} ({1})", DatabasePath, r));
            }