vb.net - SQLiteConnectionStringBuilder generates an invalid connection string -
i'm trying build valid connection string sqliteconnectionstringbuilder (system.data.sqlite v1.0.88.0) using either datasource or uri:
dim connectionbuilder = new sqliteconnectionstringbuilder connectionbuilder.datasource = path.combine(datadir, "mydatabase.sqlite") connectionbuilder.version = 3 ' open connection dim connection new sqliteconnection(connectionbuilder.connectionstring)
or:
dim connectionbuilder = new sqliteconnectionstringbuilder connectionbuilder.uri = new uri(path.combine(datadir, "mydatabase.sqlite")).absolutepath connectionbuilder.version = 3 ' open connection dim connection new sqliteconnection(connectionbuilder.connectionstring)
both generate same connection string:
uri=file:///c:/users/myusername/documents/visual%20studio%202010/projects/myproject/myproject/bin/debug/data/mydatabase.sqlite;version=3
the uri valid, connection string looks good, when try open connection, generates notsupportedexception
due path format within sqlite:
bei system.security.util.stringexpressionset.canonicalizepath(string path, boolean needfullpath) bei system.security.util.stringexpressionset.createlistfromexpressions(string[] str, boolean needfullpath) bei system.security.permissions.fileiopermission.addpathlist(fileiopermissionaccess access, accesscontrolactions control, string[] pathlistorig, boolean checkforduplicates, boolean needfullpath, boolean copypathlist) bei system.security.permissions.fileiopermission..ctor(fileiopermissionaccess access, string[] pathlist, boolean checkforduplicates, boolean needfullpath) bei system.io.path.getfullpath(string path) bei system.data.sqlite.sqliteconnection.expandfilename(string sourcefile, boolean tofullpath) in c:\dev\sqlite\dotnet\system.data. sqlite\sqliteconnection.cs:zeile 2690. bei system.data.sqlite.sqliteconnection.open() in c:\dev\sqlite\dotnet\system.data.sqlite\sqliteconnection.cs:zeile 2009.
how can prevent short of building connection string myself?
based on :
this thread (sqlite invalid uri after updating system.data.sqlite.dll)
sqlite documentation
uri
(http://www.sqlite.org/uri.html, 3.1 uri path)an ordinary filename can converted equivalent uri steps shown below. 1 exception relative windows pathname drive letter cannot converted directly uri; must changed absolute pathname first.
convert "?" characters "%3f".
convert "#" characters "%23".
on windows only, convert "\" characters "/".
convert sequences of 2 or more "/" characters single "/"character .
on windows only, if filename begins drive letter, prepend single "/" character.
prepend "file:" scheme.
and after looking @ code in sqliteconnectionstringbuilder.cs
it seems :
setting
datasource
oruri
has same effect.you should convert sequences of 2 or more "/" characters single "/" character using
string.replace()
make sure uri valid. problem in connection stringuri=file:
///c...
Comments
Post a Comment