SQLPutData - insert into image size limit

SQLPutData - insert into image size limit

Post by James Akerm » Sat, 06 Jul 2002 02:40:19


Hi,
  I am trying to store a file in a database in an 'image' column. The code I am
using (shown below) works fine for files that are below 8002 bytes in size but
any larger files fail, once more than 8001 bytes have been sent using the
SQLPutData command. It doesn't matter what size of chunks of the file I send to
the Database but once I have sent over about 8000 bytes it fails.

I am using SQLServer 2000
ODBC version 2000.80.528.00
Windows 2000

Thanks very much for any help, it is much appreciated

James.

/**********CODE BELOW************
********************************/

// Bind the data parameter
SDWORD cbValue = SQL_DATA_AT_EXEC;//SQL_LEN_DATA_AT_EXEC(Length);

retcode = SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_BINARY,
SQL_VARBINARY, Length,0, NULL, 0, &cbValue );
// Check for an error
if (retcode != SQL_SUCCESS && retcode != SQL_NEED_DATA)
        AfxThrowDBException( retcode, &theDatabase, stmt );

// Set the message text.
pMessage->SetWindowText ( "Adding file " + ActualFileName + " to database" );

Statement.Format("INSERT INTO SystemFiles ( Directory, FileName, Length, Data)
VALUES ('%s', '%s', %d, ?)",Directory, ActualFileName, Length);
retcode = SQLExecDirect( stmt, (unsigned char *)Statement.GetBuffer(256),
SQL_NTS );
Statement.ReleaseBuffer();

// Check for an error
if (retcode != SQL_SUCCESS && retcode != SQL_NEED_DATA)
        AfxThrowDBException( retcode, &theDatabase, stmt );                

// Now send the data
if (retcode == SQL_NEED_DATA) {
        DWORD dummy;
        retcode = SQLParamData(stmt,(void **)&dummy);
        if (retcode != SQL_SUCCESS && retcode != SQL_NEED_DATA)
                AfxThrowDBException( retcode, &theDatabase, stmt );                

        char Buffer[8001]; // (SQLserver max 8001 ie. 8002 fails)
        DWORD Done;
        for (;;)
        {
                ReadFile(hFile, Buffer, sizeof(Buffer), &Done, NULL);
                retcode = SQLPutData(stmt, Buffer, Done);

                if (retcode != SQL_SUCCESS && retcode != SQL_NEED_DATA)
                        AfxThrowDBException( retcode, &theDatabase, stmt );                

                // Update the progress bar...
                LengthSoFar += Done;
                pProgress->SetPos((int)((LengthSoFar * 100) / TotalLength));

                // Have we finished?
                if (Done < sizeof(Buffer))
                        break;

                // Do we stop?
                if (Stop)
                        break;

        }

        // Signal we have finished
        pMessage->SetWindowText ( "Committing "+ActualFileName );
        SQLParamData(stmt, (void **)&dummy);

Quote:}

// Free the statement
SQLFreeStmt( stmt, SQL_DROP );

// Free the file handle
CloseHandle(hFile);

 
 
 

1. Copying Image Fields - Size Limit?

Hello,

The SQL Server BOL topic "Retrieving ntext, text, or image Values" states
that:

SELECT pr_info
FROM pub_info


Does this apply only when using an API such as ODBC or will the following

INSERT INTO someTable (doc) SELECT doc FROM anotherTable

Where doc is of type Image.

I want to copy image fields between tables, the images may be several
megabytes in size.

Thanks

2. Does foreign key declare create an index?

3. Size limit on images in a database

4. Linux ER Design Tool??

5. limit to insert image

6. Send your updated resume Oracle Clinical Database P/A $95K Permanent Exton PA

7. INSERT row size limit exceeded

8. Oracle7 database size limit (or tablespace size)?

9. Row size could exeed size limit, wich iss 1962 bytes

10. Maximum Image size allowed for Image Datatype

11. Maximum Image size allowed for Image datatype.

12. Backup image size changes with different buffer sizes