SQLite database file can't be opened when placed in network folder

1.6k views Asked by At

Can someone help me to understand why this works fine...

Dim cs = "Data Source=C:\folder\Livros.sdb;Version=3;"
Dim cn = New System.Data.SQLite.SQLiteConnection(cs)
cn.Open() ' no exception 

... while this breaks when opening connection (it is exactly the same file)...

Dim cs = "Data Source=\\NetworkServer\folder\Livros.sdb;Version=3;"
Dim cn = New System.Data.SQLite.SQLiteConnection(cs)
cn.Open() ' exception: {"unable to open database file"}

... and fix it because I need to place database file in network location so I can access it regardless of the computer I run the application?

Thank you very much!

2

There are 2 answers

1
VBobCat On BEST ANSWER

Ok, so by trial and error I found the solution, although I can't quite understand the reason it works:

Dim cs = "Data Source=\\NetworkServer\folder\Livros.sdb;Version=3;"
Dim cn = New System.Data.SQLite.SQLiteConnection(cs)
cn.ParseViaFramework = True ' JUST ADDED THIS STATEMENT
cn.Open() ' no exception

If somebody can explain why .ParseViaFramework = True does the trick, please feel free to comment.

0
Cedar On

Similar question was asked here.

SQLite: Cannot open network file programmatically, even though worked before

The top answer gives a few more fixes. Linking here as this is the first stackoverflow that came up when I searched. Also I was using a SQLiteConnectionStringBuilder and could not find a way to set the parseViaFramework so the first solution was the one I needed.

  1. Double the leading two backslashes in the file name (e.g. "\\\\network\share\file.db").
  2. Use a mapped drive letter.
  3. Use the SQLiteConnection constructor that takes the parseViaFramework boolean argument and pass 'true' for that argument.