It is currently Thu, 21 Aug 2014 07:02:04 GMT



 
Author Message
 Inserting BLOB using CLongBinary/MFC

Hi everybody,

I'm desperately trying to insert BLOB / Image data of type CLongBinary via
ODBC into a database using Visual C++ 1.51, but unfortunately it doesn't work at all.

With SQL-Server ODBC 32-bit driver version 2.50.0126
or   SQL-Server ODBC 16-bit driver version 1.02.3231,
I keep getting the following error message:

(This is the first and only connection I open to the database.)

With Intersolv's ODBC driver for Informix, I get:

Using only table columns within my recordset that are not of type BLOB or image,
everything works fine!

It doesn't make any difference if the size of my BLOB is more than 64K or less.

Please help !

--------------------------------------------------------------------

More Information:

I'm using VC++ 1.51 and SQL-Server 6.0 or INFORMIX Online 5.1.

I already read through several KB articles, especially
Q140535: FIX: Only the First 64K Is Read from Binary Field
Q141352: FIX: Only 64K fo Data Transferred via CLongBinary
Q133311: BUG: Errors Occur When SQL Server Binary Field Over 64K

I also replaced the buggy version of the function RFX_LongBinary()
with the one suggested in Q133311.

Here's the code I'm using:

CMyTypeSet      rsRecord;               // type CRecordSet

// Connecting to database
rsRecord.Open(CRecordset::snapshot, NULL);
if (rsRecord.CanTransact)
{
        TRY
        {
                if (rsRecord.CanAppend())
                {
                        rsRecord.MoveNext();
                        rsRecord.AddNew();  

                        rsRecord.SetFieldDirty(NULL);
                        rsRecord.SetFieldNull(NULL, FALSE);

                        // rsRecord.m_blob is of type CLongBinary,
                        // hGlb is retrieved through GlobalAlloc()
                        // and currently not locked
                        rsRecord.m_field1                  = 1;
                        rsRecord.m_field2                  = 2;
                        rsRecord.m_field3                  = "test";
                        rsRecord.m_blob.m_hData            = hGlb;
                        rsRecord.m_blob.m_dwDataLength     =
GlobalSize(rsRecord.m_blob.m_hData);

                        if(rsRecord.CanUpdate())
                                rsRecord.Update();      // BANG!!!      
                }
        }

        CATCH_ALL(e)
        {
          .....
        }

I built my app using App Wizzard and Class Wizzard.

As I said before, using only table columns that are not of type BLOB or image
(in this example: m_field1, m_field2, m_field3), everything works fine!
And I open only one connection to the database.

Has anybody come accross a similar problem ?
Am I doing something wrong, or is this a MFC/ODBC driver bug ?
Any kind of tips, hints, code snippets are greatly appreciated!

Thanks all !

Roland

---------------------------------------------------------------------------
Email:
        roland.schna...@ufc.mts.dec.com
        roland.schna...@t-online.de



 Fri, 11 Dec 1998 03:00:00 GMT   
 
   [ 1 post ] 

Similar Threads

1.Inserting BLOB into DB using CLongBinary/MFC

Hi everybody,

I'm desperately trying to insert BLOB / Image data of type CLongBinary via
ODBC into a database using Visual C++ 1.51, but unfortunately it doesn't work at all.

With SQL-Server ODBC 32-bit driver version 2.50.0126
or   SQL-Server ODBC 16-bit driver version 1.02.3231,
I keep getting the following error message:

>Connection is busy with results for another hstmt
>State:S1000[Microsoft][ODBC SQL Server Driver]

(This is the first and only connection I open to the database.)

With Intersolv's ODBC driver for Informix, I get:

>Cannot write blob.
>Native:-605,Origin:State:S1000[INTERSOLV][ODBC Informix driver][Informix]  

Using only table columns within my recordset that are not of type BLOB or image,
everything works fine!

It doesn't make any difference if the size of my BLOB is more than 64K or less.

Please help !

--------------------------------------------------------------------

More Information:

I'm using VC++ 1.51 and SQL-Server 6.0 or INFORMIX Online 5.1.

I already read through several KB articles, especially
Q140535: FIX: Only the First 64K Is Read from Binary Field
Q141352: FIX: Only 64K fo Data Transferred via CLongBinary
Q133311: BUG: Errors Occur When SQL Server Binary Field Over 64K

I also replaced the buggy version of the function RFX_LongBinary()
with the one suggested in Q133311.

Here's the code I'm using:

CMyTypeSet      rsRecord;               // type CRecordSet

// Connecting to database
rsRecord.Open(CRecordset::snapshot, NULL);
if (rsRecord.CanTransact)
{
        TRY
        {
                if (rsRecord.CanAppend())
                {
                        rsRecord.MoveNext();
                        rsRecord.AddNew();  

                        rsRecord.SetFieldDirty(NULL);
                        rsRecord.SetFieldNull(NULL, FALSE);

                        // rsRecord.m_blob is of type CLongBinary,
                        // hGlb is retrieved through GlobalAlloc()
                        // and currently not locked
                        rsRecord.m_field1                  = 1;
                        rsRecord.m_field2                  = 2;
                        rsRecord.m_field3                  = "test";
                        rsRecord.m_blob.m_hData            = hGlb;
                        rsRecord.m_blob.m_dwDataLength     = GlobalSize(rsRecord.m_blob.m_hData);

                        if(rsRecord.CanUpdate())
                                rsRecord.Update();      // BANG!!!      
                }
        }

        CATCH_ALL(e)
        {
          .....
        }

I built my app using App Wizzard and Class Wizzard.

As I said before, using only table columns that are not of type BLOB or image
(in this example: m_field1, m_field2, m_field3), everything works fine!
And I open only one connection to the database.

Has anybody come accross a similar problem ?
Am I doing something wrong, or is this a MFC/ODBC driver bug ?
Any kind of tips, hints, code snippets are greatly appreciated!

Thanks all !

Roland

---------------------------------------------------------------------------
Email:
        roland.schna...@ufc.mts.dec.com
        roland.schna...@t-online.de

2. How to store BLOB through CLongBinary object?

3. HELP: Updating a BLOB (CLongBinary)

4. Q:BLOB<->OLE->CLongBinary

5. Using BLOBs thru ACCESS & MFC

6. how to insert value of BLOB into a memo field

7. MFC CLongBinary and Access, is it possible?

8. Passing Access Blob/OLE field to a MFC DLL

9. MFC 4.0 Database and BLOBs

10. MFC DataBase & OLE/BLOBs


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software