使用System.Data.SQLite.SQLIteDataReader.GetBlob检索BLOB字段时出错 [英] Error retrieving BLOB field using System.Data.SQLite.SQLIteDataReader.GetBlob

查看:533
本文介绍了使用System.Data.SQLite.SQLIteDataReader.GetBlob检索BLOB字段时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Due to reasons beyond my control, I am creating a .NET 2.0 assembly in which I load a SQLite database and retrieve some binary data from it. Specifically, PDF documents.

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

The documentation for System.Data.SQLite.SQLiteDataReader.GetBlob(int i, bool ReadOnly) says: (emphasis mine)


以System.Data.SQLite.SQLiteBlob对象的形式检索列。 如果查询中不包含 rowid列或其别名之一,则此方法不适用于使用WITHROW ROWID创建的表-或者-如果未使用System创建System.Data.SQLiteDataReader。 Data.CommandBehavior.KeyInfo标志。

这是我的SQLiteCommand:

Here is my SQLiteCommand:

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

我已经实例化了SQLiteDataReader,如下所示:

I have instantiated my SQLiteDataReader like so:

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

我按以下方式调用GetBlob(int i,bool ReadOnly)函数:

I call the GetBlob(int i, bool ReadOnly) function as follows:

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是否存在新版本中已解决的问题?

Am I doing something wrong? Am I missing a step? Do I need to file a bug? Is it an issue with .NET 2.0 that has been resolved in newer versions?

推荐答案

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

To make this code work, remove the System.Data.CommandBehavior.SequentialAccess flag and select at least the rowid and blob field.

这篇关于使用System.Data.SQLite.SQLIteDataReader.GetBlob检索BLOB字段时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆