Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 更新System.Data.SQLite.dll后,SQLite的URI无效_C#_Sqlite_System.data.sqlite - Fatal编程技术网

C# 更新System.Data.SQLite.dll后,SQLite的URI无效

C# 更新System.Data.SQLite.dll后,SQLite的URI无效,c#,sqlite,system.data.sqlite,C#,Sqlite,System.data.sqlite,我首先有了这个SQLite版本:1.0.77.0(SQLite-netFx40-static-binary-bundle-Win32-2010-1.0.77.0) 一切都很顺利。 将System.Data.SQLite.dll更新为1.0.82.0版(SQLite-netFx40-static-binary-bundle-Win32-2010-1.0.82.0)后,我现在收到以下信息: 无法打开数据库。连接字符串:“datetimeformat=ISO8601;同步=关闭;uri=“file:/

我首先有了这个SQLite版本:1.0.77.0(SQLite-netFx40-static-binary-bundle-Win32-2010-1.0.77.0) 一切都很顺利。 将System.Data.SQLite.dll更新为1.0.82.0版(SQLite-netFx40-static-binary-bundle-Win32-2010-1.0.82.0)后,我现在收到以下信息:

无法打开数据库。连接字符串:“datetimeformat=ISO8601;同步=关闭;uri=“file://C:/Users/username/Documents/data/test.db”;版本=3;日志模式=截断;默认隔离级别=重新提交;池=真';错误:“System.InvalidOperationException:无效的连接字符串:无效的URI”

我还尝试了file:///而不是file://而没有任何运气

有谁能告诉我我的URI有什么问题,为什么它在v1.0.82.0中不再有效,而在v1.0.77.0中有效


(1.0.82.0==3.7.14)

我认为您应该尝试将连接字符串精简到基本内容,然后添加选项

看看这个站点,例如SQLite连接字符串选项

3///仅当您试图转义uri中的空格时才有效,我还想说,您应该尝试将数据库从users文件夹移到c:\上的根目录,以防访问权限对它访问数据库无效,这也意味着您可以尝试使用更简单的连接字符串


祝您好运,请参见,但是您的URI(带有三个斜杠)看起来是正确的。

获取正确连接字符串的最佳方法是始终使用
SQLiteConnectionStringBuilder
类来生成它们

SQLiteConnectionStringBuilder conn_builder = new SQLiteConnectionStringBuilder 
{ 
   DateTimeFormat = SQLiteDateFormats.ISO8601,
   SyncMode = SynchronizationModes.Off,
   Version = 3,
   JournalMode = SQLiteJournalModeEnum.Truncate,
   DefaultIsolationLevel = System.Data.IsolationLevel.ReadCommitted,
   Pooling = true,
   Uri = new Uri(@"c:\tmp\db.sqlite").AbsoluteUri
 };
 string conn_str = conn_builder.ConnectionString;
如果
Uri
不起作用,请尝试设置
DataSource
(如果您使用的是本地文件)


快速检查显示,
DataSource
在中的
Uri
之前进行计算,并优先于它,因此,如果
Uri
处理中存在错误,使用DataSource可能有助于绕过它。

以下内容对我有效,例如下面的示例,您不能使用DataSource

FullUri=file::memory:?cache=shared
根据从版本1.0.82.0开始的更改:

通过新的FullUri连接字符串添加对URI文件名的支持 财产

例如:

var connection = new SQLiteConnection("FullUri=file:mydb.sqlite?cache=shared");

它不能使用三个斜杠(因为这是v1.0.77.0中的某种缺陷,它使用两个斜杠而不是三个斜杠)。但是在v1.0.82.0中更改此选项不起作用如果使用
数据源
字符串而不是
Uri
,会发生什么情况?还没有尝试过。。。有关于这个的文件吗?区别/限制是什么?我们使用SQLiteConnectionStringBuilder,它看起来与此完全相同(uri作为变量传递除外)。您是否尝试过使用
DataSource
以确保其他一切正常?现在,我在使用builder.DataSource=myURI.AbsoluteUri;无法打开数据库。连接字符串:“datetimeformat=ISO8601;同步=关闭;uri=file:///C:/Users/username/Documents/test.db;版本=3;日志模式=截断;默认隔离级别=重新提交;池=真';错误:“System.NotSupportedException:不支持给定路径的格式。当我使用builder.DataSource=this.Uri.AbsolutePath时,在System.Security.Util.StringExpressionSet.CanonicalizePath(字符串路径,布尔值needFullPath)中;它有时起作用。但我不确定这是否是一种好方法:我的意思是直接使用路径进入
数据源
,而根本不经过
Uri
对象。所以你说有时会有用?你是说不总是?所述文件是否可通过其他方法可靠访问?比如使用众多SQLite管理器中的一个?