使用System.Data.SQLite.SQLIteDataReader.GetBlob检索BLOB字段时出错

由于我无法控制的原因,我正在创建一个.NET 2.0程序集,在其中我加载一个SQLite数据库并从中检索一些二进制数据。 具体来说,是PDF文档。

System.Data.SQLite.SQLiteDataReader.GetBlob(int i,bool ReadOnly)的文档说:(强调我的)

将列检索为System.Data.SQLite.SQLiteBlob对象。 如果查询不包含“rowid”列或其中一个别名-OR-,如果未使用System.Data.CommandBehavior创建System.Data.SQLiteDataReader,则这对于使用ROWID -OR-创建的表不起作用.KeyInfo标志。

这是我的SQLiteCommand:

using (SQLiteCommand getBooklet = new SQLiteCommand($"SELECT \"rowid\", File_Name FROM Booklets WHERE Id = {int.Parse(key)}", dbConnection)) 

我像这样实例化了我的SQLiteDataReader:

 using (SQLiteDataReader currentCustomerReader = getBooklet.ExecuteReader(System.Data.CommandBehavior.KeyInfo & System.Data.CommandBehavior.SequentialAccess)) 

我调用GetBlob(int i,bool ReadOnly)函数如下:

 currentCustomerPdf = currentCustomerReader.GetBlob(1, true); 

我对此表示欢迎:

 System.InvalidOperationException: No RowId is available at System.Data.SQLite.SQLiteBlob.Create(SQLiteDataReader dataReader, Int32 i, Boolean readOnly) at System.Data.SQLite.SQLiteDataReader.GetBlob(Int32 i, Boolean readOnly) ... 

难道我做错了什么? 我错过了一步吗? 我需要提交错误吗? 是否已在较新版本中解决了.NET 2.0的问题?

要使此代码有效,请删除System.Data.CommandBehavior.SequentialAccess标志并至少选择rowid和blob字段。

尽管keyinfo有效,但由于executereader方法的大内存消耗(大小等于blob大小),它无法解决大blob对象的增量blob I / O. 避免大量内存使用的一种方法是在单独的查询中获取rowid并重载sqliteblob.create方法并直接传递rowid。 所以如果你可以重载sqliteblob.create方法,那么基本上不需要keyinfo。