如何将文件加载到 blob 中而不先加载到 RAM 中?

发布于 2024-08-27 01:56:28 字数 225 浏览 8 评论 0原文

我正在使用 C#,但在使用字节数组将大文件加载到二进制字段中时遇到问题。

基本上,如果我加载太大的文件,就会遇到内存问题。

有没有一种方法可以在不使用大量内存的情况下将文件加载到二进制字段中,即避免首先将文件加载到内存中?

如果有帮助的话,我正在使用 Advantage Database Server,这是使用 winforms 应用程序而不是 Web 应用程序。

问候

I am using C# and I am having trouble loading large files into a binary field use byte arrays.

Basically, if I load a file that is too large, I get memory problems.

Is there a way to load a file into a binary field without using large amounts of ram, i.e. avoid loading the file into memory first?

If it helps, I am using Advantage Database Server and this is using a winforms app not a web app.

Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

北渚 2024-09-03 01:56:28

AdsExtendedReader.SetBytes 可用于分块加载 blob。它封装了对 Jeremy 提到的 AdsSetBinary() 的调用。

请参阅 AdsExtendedReader.SetBytes

The AdsExtendedReader.SetBytes can be used to load the blob in chunks. It encapsulates the the call to the AdsSetBinary() that Jeremy mentioned.

see AdsExtendedReader.SetBytes.

辞别 2024-09-03 01:56:28

您可以直接使用 Advantage Client Engine (ACE) 并调用 AdsSetBinary API 以分块设置 blob。抱歉,我现在没有时间为您编写示例。您需要将此原型添加到您的 C# 文件中:

[DllImport("ace32.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Winapi )]
              public static extern uint AdsSetBinary( IntPtr hTable, String pucFldName, ushort usBinaryType, uint ulTotalLength, uint ulOffset, byte[] pucBuf, uint ulLen );   

这里是 C API 参考的链接:

http://devzone.advantagedatabase.com/dz/webhelp/Advantage9.1/mergedProjects/ace/api2/adssetbinary.htm

获取要传递的句柄API,请参阅 AdsExtendedReader.AdsHandle 文档。

更新:我刚刚看到 Alex 的答案,它比我的更好,我不知道我们已经使用 .NET 方法封装了 AdsSetBinary 调用。您可能想将他的答案标记为该问题的正确答案。 :)

You can use the Advantage Client Engine (ACE) directly and call the AdsSetBinary API to set the blob in chunks. Sorry I don't have time right now to write an example for you. You will need to add this prototype to your c# file:

[DllImport("ace32.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Winapi )]
              public static extern uint AdsSetBinary( IntPtr hTable, String pucFldName, ushort usBinaryType, uint ulTotalLength, uint ulOffset, byte[] pucBuf, uint ulLen );   

And here is a link to the C API reference:

http://devzone.advantagedatabase.com/dz/webhelp/Advantage9.1/mergedProjects/ace/api2/adssetbinary.htm

To get the handle to pass the API, see the AdsExtendedReader.AdsHandle documentation.

Update: I just saw Alex's answer and it is better than mine, I didn't know that we already wrapped the AdsSetBinary call with a .NET method. You might want to mark his answer as the correct answer to this question. :)

巷子口的你 2024-09-03 01:56:28

除非您选择简单地在数据库中添加对文件所在位置的引用,否则它必须首先通过内存,因此建议研究一次加载文件 x 字节的解决方案。

Unless you choose to simply add a reference in the database to where the file is located it must go through memory first, so id advise looking into a solution that loads the file x bytes at a time.

指尖凝香 2024-09-03 01:56:28

我在使用“UPDATE .WRITE”之前已经完成了此操作,我从流中读取文件块并将数据附加到数据库字段。在此页面上搜索 .WRITE: http://msdn.microsoft.com/ en-us/library/ms177523.aspx

不幸的是,这是针对 SQL Server 的。我认为 Advantage Database Server 在这里会有所不同,但这也许会给您带来正确的方向。

I've done this before using "UPDATE .WRITE" I read chunks of the file from a stream and append the data to the database field. Search for .WRITE on this page: http://msdn.microsoft.com/en-us/library/ms177523.aspx.

Unfortunately that is for SQL Server. I think Advantage Database Server will vary a bit here, but maybe this will send you in the right direction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文