3

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

Ace Grace
  • 631
  • 1
  • 7
  • 21

4 Answers4

5

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.

Mark Wilkins
  • 40,729
  • 5
  • 57
  • 110
Alex W
  • 3,283
  • 1
  • 19
  • 25
2

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. :)

Jeremy Mullin
  • 4,170
  • 4
  • 36
  • 54
0

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.

0

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.

David Hogue
  • 1,791
  • 1
  • 14
  • 23