Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Delphi 10.1 Berlin Save BLOB to File Corruption


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Apr 24, 2017 4:13 PM Last Post By: Registered User Threads: [ Previous | Next ]
Alphonso Willis

Posts: 1
Registered: 12/21/08
Delphi 10.1 Berlin Save BLOB to File Corruption  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2016 8:44 AM
I hope this is the correct forum to post this issue.

Installation Details:
RAD Studio 10.1 Berlin 64-bit
dbExpress using MSSQL driver
Windows 7 64-bit
Microsoft Office 32-bit

Problem:
I am migrating a large application from Delphi 2009 to 10.1 Berlin. It is a 32-bit Windows application. I store various types of documents as BLOBs in data tables. The different types are text, AutoCAD (DWG) drawing files and Microsoft Excel files. (My Microsoft Office installation is 32-bit).

The file sizes range from 10 KB to 4,000 KB. I have never had an issue with storing and retrieving any of those file types using Delphi 2009. However on Delphi 10.1 when I try to save to file MS Excel files over 1 MB in size, the files are corrupted. Under my Delphi 2009 there is no problem. I am certain that loading the file to the data table is working for both Delphi 2009 and Delphi 10.1. I tested this by loading the Excel file to the data table from the Delphi 10.1 application and then saving the file to disk using the Delphi 2009 application. The file was OK. The Delphi 2009 application works on both the load from file to data table and save to file from data table operations. The Delphi 10.1 application works on the load from file to data table and but fails on the save to file from data table. When I say "fails", I mean that the file is saved to disk, but when I attempt to open the Excel document, Excel says that there is a problem with the file and wants to recover data. If I say yes, the result is a spreadsheet with a lot of missing data.

In my case this seems to only impact Excel files. I performed load/save operations on with Delphi 10.1 with file sizes up to 5 MB in size.

I have tried 2 different methods to save the BLOBs to disk. Both methods fail when the spreadsheet is over 1MB in size.

Method 1:
(cds.FieldByName('TEMPLATE') as TBLOBField).SaveToFile(FullPath);
if not FileExists(FullPath) then
begin
MessageBeep(mb_IconHand);
MessageDlg('Template file, ' + FullPath + ', could not be found after copy from template table. ', mtError,[mbOK],0);
Exit;
end;

Method2:
cds.Edit;
blob := cds.CreateBlobStream(cds.FieldByName('TEMPLATE'), bmRead);
try
blob.Seek(0, soFromBeginning);
with TFileStream.Create(FullPath, fmCreate) do
try
CopyFrom(blob, blob.Size);
finally
Free;
end;
finally
blob.Free;
end;

This is how my TSQLConnection component is configured on the parameters:

SchemaOverride=%.dbo
DriverUnit=Data.DBXMSSQL
DriverPackageLoader=TDBXDynalinkDriverLoader,DBXCommonDriver240.bpl
DriverAssemblyLoader=Borland.Data.TDBXDynalinkDriverLoader,Borland.Data.DbxCommonDriver,Version=24.0.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b
MetaDataPackageLoader=TDBXMsSqlMetaDataCommandFactory,DbxMSSQLDriver240.bpl
MetaDataAssemblyLoader=Borland.Data.TDBXMsSqlMetaDataCommandFactory,Borland.Data.DbxMSSQLDriver,Version=24.0.0.0,Culture=neutral,PublicKeyToken=91d62ebb5b0d1b1b
GetDriverFunc=getSQLDriverMSSQL
LibraryName=dbxmss.dll
VendorLib=sqlncli10.dll
VendorLibWin64=sqlncli10.dll
MaxBlobSize=-1
OSAuthentication=False
PrepareSQL=True
DriverName=MSSQL
HostName=XXX\XXX_3
DataBase=DB
User_Name=IM
Password=$$$$
BlobSize=-1
ErrorResourceFile=
LocaleCode=0000
IsolationLevel=ReadCommitted
OS Authentication=False
Prepare SQL=False
ConnectTimeout=60
Mars_Connection=False

I'm beginning to wonder if I should have chosen the 64-bit installation of Delphi 10.1 since I don't have a current need to develop a 64-bit installation. Can someone please point me in the right direction on this?

Thanks,

Al
Registered User

Posts: 46
Registered: 3/4/05
Re: Delphi 10.1 Berlin Save BLOB to File Corruption  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 24, 2017 4:13 PM   in response to: Alphonso Willis in response to: Alphonso Willis
I had some issues with sending image files over datasnap - which uses some Remanence of DBX

I had to encode and decode my streams as Base64 for the images to transfer without issue.

Not sure it this might help your situation - save your blobs as base64 and then decode them when saving back to files?

TNetEncoding.Base64

has the methods
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02