Question

Hi, I have installed the sqlite-net nuget package, which comes with 2 cs files: SQLite.cs and SQLiteAsync.cs.

SQLite.cs contains a class called SQLite3 which contains the method:

[DllImport("sqlite3", EntryPoint = "sqlite3_win32_set_directory", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]
public static extern int SetDirectory(uint directoryType, string directoryPath);

I see that the SQLiteConnection constructor has the following code:

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

But why?! What does this do and why does it need to be set each time a new SQLiteConnection is created? It seems like I get sporadic AccessViolationExceptions with this line.

Update

I found the documentation for this method but still don't understand the purpose of the TempDirectory. What gets written there?

/*
** This function sets the data directory or the temporary directory based on
** the provided arguments.  The type argument must be 1 in order to set the
** data directory or 2 in order to set the temporary directory.  The zValue
** argument is the name of the directory to use.  The return value will be
** SQLITE_OK if successful.
*/
Was it helpful?

Solution

The specific call that you show from the SQLiteConnection constructor sets the temporary directory for SQLite. This is the directory that SQLite uses for temporary/ working storage.

I believe that because of app sandboxing, SQLite is unable to write to the default temp directory; this is why the code that you quoted uses the application's temp directory.

If the directory is not set, the side effect is that you get errors when executing update statements.

See more here:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top