SQLite User Forum

SQLite - error initializing database in redirected folder
Login

SQLite - error initializing database in redirected folder

(1) By anonymous on 2022-09-19 12:09:24 [link] [source]

Hi, I encountered a problem, that i can't solve myself. Is it SQLite bug maybe?

I'm using %appdata% folder to save and store settings of my .Net framework app using SQLite database. Everything works fine, until some clients use folder redirection in Windows. As long, as redirected folder points to local directory, it is still fine, but when it's somewhere in the network, trying to open or create a database always throws a exception:

> An exception occurred while initializing the database. See the InnerException for details.
>> The underlying provider failed on Open.
>>> unable to open database file

As it turns out, despite having correct path set in code (like '\\server_name\test' or '\\server_ip_adress\test', according to Process Monitor, my app tries to create a database file at 'C:\server_name\test', but it fails as that catalog doesn't exist.

Is it my mistake, or is it a SQLite bug? There is no problem creating files or folders in that redirected folder using code. In the link below, I provided a sample code to show how I'm trying to initialize a database:
https://drive.google.com/file/d/1mZZYoSucEGd8dPP6zW1TcTQUFRtJPOrT/view?usp=sharing

Also, a link showing how to set a folder redirection on excample of Downloads folder:
https://learn.microsoft.com/en-us/answers/questions/505427/how-do-i-redirect-a-folder-programmatically-specia.html

(2) By Chris Locke (chrisjlocke1) on 2022-09-19 13:44:29 in reply to 1 [link] [source]

Is this using the system.data.sqlite.dll library?

If you're using the network, you have to use the .ParseViaFramework (setting it to true) property.

(3) By anonymous on 2022-09-20 07:47:52 in reply to 2 [link] [source]

Yes, I'm using System.Data.SQLite.dll I have already tried creating SQLiteConnection with parseViaFramework set to true, nothing changed.

(4.1) By Chris Locke (chrisjlocke1) on 2022-09-22 10:23:54 edited from 4.0 in reply to 1 [source]

Your program is clear and shows 'Data Source=", sQLiteDBPath' - so have you logged what this value is? Is the value actually

\\server\directory\test1\test2\config.db
?

(5) By anonymous on 2022-09-20 12:14:50 in reply to 4.0 [link] [source]

Yes, exactly, that is the value passed to SQLiteConnection constructor. The same exception is thrown even if the path to database file in a redirected folder is hardcoded. It also doesn't seem to matter whether I'm using forward or backslashes in the path.

(9) By Chris Locke (chrisjlocke1) on 2022-09-22 10:33:58 in reply to 5 [link] [source]

For the avoidance of doubt, and lets assume the server is called banana and the user is grape, what is the actual real path of the database? This would change for each user, but for a problematic one, would it be

\\banana\users\grape\profile\appdata\test1\test2\config.db

Is there a share on banana that the user grape can write to? eg, \\banana\documents ? If you set the path to that, does that work OK? This rules out network access issues, etc.

(10) By anonymous on 2022-09-23 07:46:23 in reply to 9 [link] [source]

For one of our clients the path would be \bananaDocumentsgrapeAppDataRoamingconfig.db

For my test, I use the server that I have full admin rigths to. Using code there is no problem creating file \bananatest1test2Logslog1.log or \bananatest1test2file1.xml including creating folders to represent that path, but creating a SQLite db file throws an exception. Perhaps wrongly I assumed, it might be a SQLite bug, but I no longer have any ideas what to do with it.

Were you able to recreate that problem with a sample code I provided?

(11) By Chris Locke (chrisjlocke1) on 2022-09-23 10:16:14 in reply to 10 [link] [source]

Not directly, as I don't run on a server - my code would return a local directory.

Was this test code then?

line 12 has private static string _filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "test1", "test2", "config.db");

This is why I asked if it was in the test1\test2\config.db path - these folders are getting appended.

I assume this makes sense.

(12) By anonymous on 2022-09-23 10:29:00 in reply to 11 [link] [source]

Yes, it was posted to show my approach to creating databases. For me it throws exception 100% of the time, when appdata folder is redirected to remote location. It doesn't matter whether I use SpecialFolder.ApplicationData, Desktop, MyPictures or any other, also if I use test1 and test2 tree, or just specify the special folder as a location to save the file.

I'm also sure, that at all times required paths existed.

(13) By Chris Locke (chrisjlocke1) on 2022-09-23 13:20:10 in reply to 12 [link] [source]

OK, so on \\server\banana ensure there is a share the user grape can write to.

Set that database location temporarily in your code - \\server\grape\directory\config.db

No test1 or test2 combine statements - just 'hard code' that database location.

Theoretically, it should work. That'll at least prove if its your network, config, etc.

(14) By anonymous on 2022-09-27 04:49:24 in reply to 13 [link] [source]

I've tried all that already - still doesn't work. Users have rights to write/read in that folder, also hardcoding different kinds of paths didn't solve the problem.

(6) By anonymous on 2022-09-21 08:10:40 in reply to 1 [link] [source]

Two clients of ours have this problem already. One of them fixed it by 'changing the configuration of GPO profiles and changing local configuration', whatever it means. This worked for all but one computer for him, but he managed to get the last one working somehow anyway. He won't tell us any more details about what and why he did to make it work, but obviously he hasn't changed any of the code.

Also running the program as administrator solves the problem, but it's not acceptable solution for our clients - end users often can't have admin rights.

(7) By anonymous on 2022-09-22 09:12:09 in reply to 1 [link] [source]

Do you have any more ideas about what to do next or how the problem could have been solved by the client? I have to have a solution soon, but I'm fairly stuck for about two weeks now.

(8) By Chris Locke (chrisjlocke1) on 2022-09-22 10:28:51 in reply to 7 [link] [source]

system.data.sqlite.dll has no problems using a network path, apart from the additional switch I mentioned so the problem could be in the additional framework you're using? It's no SQLite bug though (system.data.sqlite.dll is just a wrapper which uses SQLite, so has nothing directly to do with SQLite...)

(15) By anonymous on 2022-09-27 04:55:28 in reply to 8 [link] [source]

I wonder now whether it's Entity Framework related. Exception is beeing thrown when calling Database.Initialize(true), where Database object and it's Initialize method are defined in System.Data.Entity. I'm not sure is it more on SQLite or EF side.