Board index » delphi » Inserting a Graphic(BLOB) in a MSSQL Server 2000 table

Inserting a Graphic(BLOB) in a MSSQL Server 2000 table

Hi,

I have tried with the following code but I get always an error (Invalid Blob
Length) when I post the new inserted record. When I try the same with
Paradox, it works fine.

Does anyone know where the problem is? Or is there other solutions (with
TQuery? for the time being I prefer to still use BDE but if a simple ADO
solution exists, why not?)

Thanks a lot and best regards,

Hubert Rtif.

var
    imgBStream: TBlobStream;
    imgFStream: TFileStream;
begin
    OpenDialog1.FileName := ' ';
    OpenDialog1.Filter := 'Graphic files (*.*)|*.*';
    OpenDialog1.Options := [ofFileMustExist, ofNoValidate, ofHideReadOnly];
    if OpenDialog1.Execute then
    begin
        with dmTrans.tblProduct do // this is a TTable component
        begin
            imgBStream := TBlobStream.Create( (FieldByName( 'ART_IMAGE' ) as
TBlobField), bmWrite );
            try
                imgFStream := TFileStream.Create( OpenDialog1.FileName,
fmOpenRead );
                try
                    imgBStream.CopyFrom( (imgFStream as TStream),
imgFStream.Size);
                finally
                    imgFStream.Free;
                end;
           finally
                imgBStream.Free;
          end;
    end;
end;

 

Re:Inserting a Graphic(BLOB) in a MSSQL Server 2000 table


How about just using:
(FieldByName( 'ART_IMAGE' ) as TBlobField).LoadFromStream and SaveToStream?

I do this occasionally and have never had a problem.

Quote
"Hubert Rtif" <hubert.re...@eisbic.ch> wrote in message

news:3df7a580@newsgroups.borland.com...
Quote
> Hi,

> I have tried with the following code but I get always an error (Invalid
Blob
> Length) when I post the new inserted record. When I try the same with
> Paradox, it works fine.

> Does anyone know where the problem is? Or is there other solutions (with
> TQuery? for the time being I prefer to still use BDE but if a simple ADO
> solution exists, why not?)

> Thanks a lot and best regards,

> Hubert Rtif.

> var
>     imgBStream: TBlobStream;
>     imgFStream: TFileStream;
> begin
>     OpenDialog1.FileName := ' ';
>     OpenDialog1.Filter := 'Graphic files (*.*)|*.*';
>     OpenDialog1.Options := [ofFileMustExist, ofNoValidate,
ofHideReadOnly];
>     if OpenDialog1.Execute then
>     begin
>         with dmTrans.tblProduct do // this is a TTable component
>         begin
>             imgBStream := TBlobStream.Create( (FieldByName( 'ART_IMAGE' )
as
> TBlobField), bmWrite );
>             try
>                 imgFStream := TFileStream.Create( OpenDialog1.FileName,
> fmOpenRead );
>                 try
>                     imgBStream.CopyFrom( (imgFStream as TStream),
> imgFStream.Size);
>                 finally
>                     imgFStream.Free;
>                 end;
>            finally
>                 imgBStream.Free;
>           end;
>     end;
> end;

Re:Inserting a Graphic(BLOB) in a MSSQL Server 2000 table


Your file is too big.  In the BDE administrator, you change the Blob Size to
accomodate bigger sizes - default is only 32 kb.  You can change it to 1000
kb.  I have had the same problem, and this helped.
Quote
BlueGI <giwachowNOS...@bcw-usa.com> wrote in message

news:3df7a849$1@newsgroups.borland.com...
Quote
> How about just using:
> (FieldByName( 'ART_IMAGE' ) as TBlobField).LoadFromStream and
SaveToStream?

> I do this occasionally and have never had a problem.

> "Hubert Rtif" <hubert.re...@eisbic.ch> wrote in message
> news:3df7a580@newsgroups.borland.com...
> > Hi,

> > I have tried with the following code but I get always an error (Invalid
> Blob
> > Length) when I post the new inserted record. When I try the same with
> > Paradox, it works fine.

> > Does anyone know where the problem is? Or is there other solutions (with
> > TQuery? for the time being I prefer to still use BDE but if a simple ADO
> > solution exists, why not?)

> > Thanks a lot and best regards,

> > Hubert Rtif.

> > var
> >     imgBStream: TBlobStream;
> >     imgFStream: TFileStream;
> > begin
> >     OpenDialog1.FileName := ' ';
> >     OpenDialog1.Filter := 'Graphic files (*.*)|*.*';
> >     OpenDialog1.Options := [ofFileMustExist, ofNoValidate,
> ofHideReadOnly];
> >     if OpenDialog1.Execute then
> >     begin
> >         with dmTrans.tblProduct do // this is a TTable component
> >         begin
> >             imgBStream :=

TBlobStream.Create( (FieldByName( 'ART_IMAGE' )

- Show quoted text -

Quote
> as
> > TBlobField), bmWrite );
> >             try
> >                 imgFStream := TFileStream.Create( OpenDialog1.FileName,
> > fmOpenRead );
> >                 try
> >                     imgBStream.CopyFrom( (imgFStream as TStream),
> > imgFStream.Size);
> >                 finally
> >                     imgFStream.Free;
> >                 end;
> >            finally
> >                 imgBStream.Free;
> >           end;
> >     end;
> > end;

Other Threads