How to insert an image into SQL Server? 
Author Message
 How to insert an image into SQL Server?
Environment:  VC 6.0, SQL Server 7.0, ADO 2.1,  WinNT

I am trying to insert an image file into a SQL Server table and so far am
not having much success.
I am using CFile to read the contents into a char[] which indicates in its
return value that I have gotten the entire file.  Where I seem to be stuck
is how to get it into SQL Server from there.
What I've tried.
Approach 1:  Stored proc.   Attempt to format a CString with the statement:
Insert_Img '<char array here>'
What happens, of course, when I try to format the string is that the copy of
the character array stops with the first Zero it finds.
  Result:  Incomplete data is inserted into SQL Server

Approach 2:  ADODB::Recordset->AddNew  Attempts to coerce the character
array into a VARIANT (type VT_BSTR) seem to be failing.  I attempt to create
a BSTR using the char array as in:
CComBSTR bStr(pbuf);
The reported length returned from bStr.Length() shows that this is also
truncated at the first zero.

How do I get an image into SQL Server?

Thanks!

Steve Barta
Software Developer
Sunquest, Tucson



Fri, 28 Dec 2001 03:00:00 GMT  
 How to insert an image into SQL Server?
Check out AOTBLOB sample in the Microsoft KB
It uses the ATL DB Templates


Quote:
> Environment:  VC 6.0, SQL Server 7.0, ADO 2.1,  WinNT

> I am trying to insert an image file into a SQL Server table and so far am
> not having much success.
> I am using CFile to read the contents into a char[] which indicates in its
> return value that I have gotten the entire file.  Where I seem to be stuck
> is how to get it into SQL Server from there.
> What I've tried.
> Approach 1:  Stored proc.   Attempt to format a CString with the
statement:
> Insert_Img '<char array here>'
> What happens, of course, when I try to format the string is that the copy
of
> the character array stops with the first Zero it finds.
>   Result:  Incomplete data is inserted into SQL Server

> Approach 2:  ADODB::Recordset->AddNew  Attempts to coerce the character
> array into a VARIANT (type VT_BSTR) seem to be failing.  I attempt to
create
> a BSTR using the char array as in:
> CComBSTR bStr(pbuf);
> The reported length returned from bStr.Length() shows that this is also
> truncated at the first zero.

> How do I get an image into SQL Server?

> Thanks!

> Steve Barta
> Software Developer
> Sunquest, Tucson



Fri, 28 Dec 2001 03:00:00 GMT  
 How to insert an image into SQL Server?
Thanks for the suggestion.  I didn't find AOTBLOB in the KB but your
suggestion prompted me to look a little farther in the TechNet and I did
find AdoVcChunck which gave me the syntax I was looking for.

Quote:

>Check out AOTBLOB sample in the Microsoft KB
>It uses the ATL DB Templates



>> Environment:  VC 6.0, SQL Server 7.0, ADO 2.1,  WinNT

>> I am trying to insert an image file into a SQL Server table and so far am
>> not having much success.
>> I am using CFile to read the contents into a char[] which indicates in
its
>> return value that I have gotten the entire file.  Where I seem to be
stuck
>> is how to get it into SQL Server from there.
>> What I've tried.
>> Approach 1:  Stored proc.   Attempt to format a CString with the
>statement:
>> Insert_Img '<char array here>'
>> What happens, of course, when I try to format the string is that the copy
>of
>> the character array stops with the first Zero it finds.
>>   Result:  Incomplete data is inserted into SQL Server

>> Approach 2:  ADODB::Recordset->AddNew  Attempts to coerce the character
>> array into a VARIANT (type VT_BSTR) seem to be failing.  I attempt to
>create
>> a BSTR using the char array as in:
>> CComBSTR bStr(pbuf);
>> The reported length returned from bStr.Length() shows that this is also
>> truncated at the first zero.

>> How do I get an image into SQL Server?

>> Thanks!

>> Steve Barta
>> Software Developer
>> Sunquest, Tucson



Sat, 29 Dec 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to insert image into SQL Server?

2. images from sql server to image object

3. Trying to insert data into SQL Server

4. SQL Server: Slow INSERT performance??

5. Inserting a Delimited Text File into SQL Server

6. Insert in SQL Server CTable<CDynamicAccessor>

7. OLEDB, Fail Insert, SQL Server 7

8. Inserting Muliple Records into SQL-SERVER Database

9. Inserting a Delimited Text File into SQL Server

10. Inserting a Delimited Text File into SQL Server

11. Inserting in to a SQL Server Database

12. connect to sql server and insert

 

 
Powered by phpBB® Forum Software