OutOfMemory error inserting a very large file in a blob
Posted: Wed 14 Jul 2010 17:14
Hello I am getting errors in trying to insert very large files into the database. This is a BLOCKING ERROR FOR ME, please check and confirm it is a SDAC bug.
I am using filestream, initially I thought this was a problem of fielstream, but then I tried the same without filestream and I realized that the problem is still there.
I had this problem by trying to insert in a varbinary(max) field a big file. I tried with different file sizes:
with 465 MB it works
with 560 MB it doesn't
It gives an error.
As I try to insert the document after a while I have the following exception:
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EOutOfMemory with message 'Out of memory'.
---------------------------
Break Continue Help
---------------------------
The exception comes from CLRClasses.pas:
class function Marshal.ReallocHGlobal(pv: pointer; cb: pointer): pointer;
begin
Result := pv;
ReallocMem(Result, Integer(cb)); -- EXCEPTION COMES FROM HERE!!!
end;
I can send you a sample anyway it is very easy to create by following the following instructions.
TO REPRODUCE IT ADD THIS TABLE TO A NEW DATABASE:
Create a new Delphi project and on a form drop a TMSConnection and a TMSQuery with the following sqlcode:
then drop a button with this code on the OnClick event:
Of course try with a file that is larger than 560MB.
I am using SDAC 4.80.0.59 - Delphi 2009. I reproduced the problem on XP, Vista and 7.
I am using filestream, initially I thought this was a problem of fielstream, but then I tried the same without filestream and I realized that the problem is still there.
I had this problem by trying to insert in a varbinary(max) field a big file. I tried with different file sizes:
with 465 MB it works
with 560 MB it doesn't
It gives an error.
As I try to insert the document after a while I have the following exception:
---------------------------
Debugger Exception Notification
---------------------------
Project Project1.exe raised exception class EOutOfMemory with message 'Out of memory'.
---------------------------
Break Continue Help
---------------------------
The exception comes from CLRClasses.pas:
class function Marshal.ReallocHGlobal(pv: pointer; cb: pointer): pointer;
begin
Result := pv;
ReallocMem(Result, Integer(cb)); -- EXCEPTION COMES FROM HERE!!!
end;
I can send you a sample anyway it is very easy to create by following the following instructions.
TO REPRODUCE IT ADD THIS TABLE TO A NEW DATABASE:
Code: Select all
CREATE TABLE [dbo].[DOC_FILES](
[ID_DOC_FILE] [int] NOT NULL,
[DOCUMENT] varbinary(MAX) NULL
CONSTRAINT [PK_DOC_FILES] PRIMARY KEY CLUSTERED
(
[ID_DOC_FILE] ASC
)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
Code: Select all
INSERT INTO DOC_FILES(ID_DOC_FILE, DOCUMENT)
VALUES(:ID_DOC_FILE, :DOCUMENT)
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
var
sFilePath: String;
begin
sFilePath := 'D:\Test\VeryBigFile.dat';
sqlInsertDoc.ParamByName('ID_DOC_FILE').AsInteger := 1;
sqlInsertDoc.ParamByName('DOCUMENT').LoadFromFile(sFilePath, ftblob);
sqlInsertDoc.Execute;
sqlInsertDoc.Close;
end;
I am using SDAC 4.80.0.59 - Delphi 2009. I reproduced the problem on XP, Vista and 7.