. NET version SQLite cannot access the network location of the database file-winopen,os_win.c 36702 exception

Source: Internet
Author: User
Tags sqlite sqlite database

A recent C # applet that wants to place the SQLite database on a network share for simultaneous access by multiple clients. It is found that SQLite does not connect to the database on that network location, and if the database is local, everything is fine.

For example, put the SQLite database Test.dat in a shared location: \\System\Data\test.dat,
When you create a database connection via SQLite, an exception is thrown when you execute open:

SQLite Error: os_win.c:36702: (3) Winopen (D:\System\Data\test.dat)-The system cannot find the path specified.
SQLite Error: os_win.c:36702: (3) Winopen (D:\System\Data\test.dat)-The system cannot find the path specified.
SQLite Error: Cannot open file at line 36711 of [9491ba7d73]
The first chance exception of type "System.Data.SQLite.SQLiteException" occurs in System.Data.SQLite.dll
System.Data.SQLite.SQLiteException (0x80004005): Unable to open database file
In System.Data.SQLite.SQLite3.Open (String strFileName, Sqliteconnectionflags connectionflags, Sqliteopenflagsenum Openflags, Int32 maxpoolsize, Boolean usepool)
In System.Data.SQLite.SQLiteConnection.Open ()
In MyMemory.Frame.DAL.SQLiteRunner. ctor (String connectionString) position D:\Work\Program\WPF\MyMemory\MyMemory.Frame\DAL\SQLiteRunner.cs: line number 34
In MyMemory.Frame.DAL.DatabaseServices.CreateConnection () position d:\Work\Program\WPF\MyMemory\MyMemory.Frame\DAL\ DatabaseServices.cs: Line No. 23
In MyMemory.Frame.DAL.DatabaseServices.Initialize (String datadir) position d:\Work\Program\WPF\MyMemory\MyMemory.Frame\ Dal\databaseservices.cs: Line No. 54
The first chance exception of type "System.Data.SQLite.SQLiteException" occurs in MyMemory.Frame.dll
System.Data.SQLite.SQLiteException (0x80004005): Unable to open database file
In System.Data.SQLite.SQLite3.Open (String strFileName, Sqliteconnectionflags connectionflags, Sqliteopenflagsenum Openflags, Int32 maxpoolsize, Boolean usepool)
In System.Data.SQLite.SQLiteConnection.Open ()
...

That is, the incoming SQLite network share path (beginning with \ \) is transformed into a local path within SQLite!

The problem is in the set provided by SQLite, then has the latest version of SQLite fixed the problem (or from a version intentionally, not allowing access to files on the network share location)?
To the official website Http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki Download the latest version (System.Data.SQLite 1.0.94.0 ( 3.8.6)) is replaced with a retry, or the above exception occurs.

Well, since it's open source, download the source code and see what the reason is.

After downloading, you can enter a database link using the VS compilation, which comes with the test project in the solution:

Click Run to enter the breakpoint debugging.

Nonsense less, directly on the result:

The method invocation procedure for the open process problem point is as follows

\sqlite-netfx-source-1.0.94.1\system.data.sqlite\sqliteconnection.cs Line 2372
Sortedlist<string, string> opts = parseconnectionstring (
_connectionstring, _parseviaframework);

\sqlite-netfx-source-1.0.94.1\system.data.sqlite\sqliteconnection.cs Line 1875
Arparts = Sqliteconvert.newsplit (S, '; ', true, ref error);

\sqlite-netfx-source-1.0.94.1\system.data.sqlite\sqliteconvert.cs Line 716
if ((character! = Escapechar) &&
(character! = QuoteChar) &&
(character! = separator))

Put the above if (//(character! = Escapechar) && comment off the second half of the line (note: This method of commenting code is not recommended)
(character! = QuoteChar) &&
(character! = separator))

Recompile, re-execute Test.exe everything OK.

As to why this restriction is available, the comments in the source code are:

--line 709
Hack:only consider the escape character to being an actual
"Escape" if it is followed by a reserved character;
Otherwise, emit the original escape character and
The current character in a effort to help preserve
The original string content.
--line 715

The official document says that the SQLite database, which is placed in a network location to share access, is vulnerable in certain situations. It seems that the problem of the great God is not good, ready to simply block out the use of this way.

As a reminder, the SQLite source defaults to the. NET Framework 4.5, which is compiled with the. NET Framework version that is required for the project to switch to.

Finally, the revised System.Data.SQLite.dll. Net Framework version 4.0 is available:
Download

Reprint please indicate the source.

(End of full text)


. NET version SQLite cannot access the network location of the database file-winopen,os_win.c 36702 exception

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.