【问题标题】:Store binary content into sqlite db将二进制内容存储到 sqlite db
【发布时间】:2014-04-11 02:50:45
【问题描述】:

我将图像存储到 sqlite 数据库中。指定的类型是图像字段的 BLOB。下面是存储它的代码,

FileInfo uploadedFileInfo = new FileInfo(Filename);
FileStream fs = fileInfo.OpenRead();
byte[] content = new byte[fs.Length];
fs.Read(content, 0, content.Length);
fs.Close();

并将此内容存储到数据库中。有时归档;加载失败。 此 c# 代码在 64 位机器中作为 Windows 服务运行。目标是 AnyCPU。 代码中是否有问题。还是我需要将目标设置为 x86。欢迎蚂蚁反馈! 问候

【问题讨论】:

  • 您遇到什么错误?发布错误!
  • 除此之外,您忽略了Read 的返回值,这绝不是一个好主意。但是您没有提示“有时文件上传失败”是什么意思。

标签: c# binary


【解决方案1】:

SQLite 是一个原生组件,因此您需要将 interop.dll 放在单独的文件夹中(在 System.Data.SQLite.dll 下方)

/System.Data.SQLite.dll (core assembly)
/x86/SQLite.Interop.dll (x86 native interop assembly)
/x64/SQLite.Interop.dll (x64 native interop assembly)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-29
    • 2012-04-09
    • 1970-01-01
    • 1970-01-01
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多