DBLIB bcp_sendrow fails with no error message 
Author Message
 DBLIB bcp_sendrow fails with no error message

Hello all,

  I've got a winnt console program (mfc included) that opens up a binary
flat file and then uses the bcp functions to bind and upload the data to the
sql server.  I bind all colomns in the table to program vars and load them
without any errors.  When I make the call to bcp_sendrow it fails and I get
no errormessages through my callback errhandler.  I know that the error
handler is bound properly, because I've gotten messages from it when I had a
problem with a bcp_bind call.  I've triple checked that all the binds are
correct.  I'm logging in as sa, and made sure that I've got full rights to
the table and database.  This has really got me stumped, since it dies with
no error message.

  Any ideas or suggetions would be great.

Loren Luke
System Development
Myriad Systems, Inc.

Here is the relevent offending code:
            // init the dblib
            dbinit();

            // install error and message handlers
            dberrhandle (ErrorHandler);
            dbmsghandle (MessageHandler);

            // Open and clean up the database
            login = dblogin(); // Get a LOGINREC
            if(BCP_SETL(login, TRUE) == FAIL) { // Enable bulk copy
functions
                cout << "BCP_SETL FAILED" << endl;
                return 1;
            }

            if(DBSETLUSER(login, sUserName) == FAIL) { // Set the user name
                cout << "DBSETLUSER FAILED for UserName: " << sUserName <<
endl;
                return 1;
            }

            if(DBSETLPWD(login, sPassword) == FAIL) {  // and password
                cout << "BCP_SETL FAILED for Password: " << sPassword <<
endl;
                return 1;
            }

            dbproc = dbopen(login, sSqlServerName); // Get the DBPROCESS
struct for server communication
            if(dbuse(dbproc, sDatabaseName) == FAIL) { // Use the database
that was passed in
                cout << "dbuse FAILED for Database: " << sDatabaseName <<
endl;
                return 1;
            }

            if(dbcmd(dbproc, "delete Recon") == FAIL) { // Delete all rows
from the table
                cout << "dbuse FAILED for Database: " << sDatabaseName <<
endl;
                return 1;
            }

            if(dbsqlexec(dbproc) == FAIL) { // execute the sql command
                cout << "dbsqlexec FAILED" << endl;
                return 1;
            }

            if(dbclose(dbproc) == FAIL) {
                cout << "dbclose FAILED!" << endl;
                return 1;
            }

            dbproc = dbopen(login, sSqlServerName); // Get the DBPROCESS
struct for server communication
            if(bcp_init(dbproc, sDatabaseName + "..Recon", NULL, NULL,
DB_IN) == FAIL) { // Init the table for bulk copy commands
                cout << "bcp_init for the Recon Table FAILED!" << endl;
                return 1;
            }

            // Bind local vars to the database columns
            if(bcp_bind(dbproc, (BYTE *)OriginalSequence, 0, (DBINT)10,
(BYTE *)"", 1, SQLCHAR, 2) == FAIL) {
                cout << "bcp_bind for OriginalSequence FAILED!" << endl;
                return 1;
            }

            if(bcp_bind(dbproc, (BYTE *)Account, 0, (DBINT)10, (BYTE *)"",
1, SQLCHAR, 3) == FAIL) {
                cout << "bcp_bind for Account FAILED!" << endl;
                return 1;
            }

            if(bcp_bind(dbproc, (BYTE *)Serial, 0, (DBINT)10, (BYTE *)"", 1,
SQLCHAR, 4) == FAIL) {
                cout << "bcp_bind for Serial FAILED!" << endl;
                return 1;
            }

            if(bcp_bind(dbproc, (BYTE *)TranCode, 0, (DBINT)6, (BYTE *)"",
1, SQLCHAR, 5) == FAIL) {
                cout << "bcp_bind for TranCode FAILED!" << endl;
                return 1;
            }

            if(bcp_bind(dbproc, (BYTE *)Amount, 0, (DBINT)11, (BYTE *)"", 1,
SQLCHAR, 6) == FAIL) {
                cout << "bcp_bind for Amount FAILED!" << endl;
                return 1;
            }

            if(bcp_bind(dbproc, (BYTE *)OriginalDate, 0, (DBINT)10, (BYTE
*)"", 1, SQLCHAR, 7) == FAIL) {
                cout << "bcp_bind for OriginalDate FAILED!" << endl;
                return 1;
            }

            if(bcp_bind(dbproc, (BYTE *)ImageCode, 0, (DBINT)3, (BYTE *)"",
1, SQLCHAR, 8) == FAIL) {
                cout << "bcp_bind for ImageCode FAILED!" << endl;
                return 1;
            }

            if(bcp_bind(dbproc, (BYTE *)Sequence, 0, (DBINT)12, (BYTE *)"",
1, SQLCHAR, 9) == FAIL) {
                cout << "bcp_bind for Sequence FAILED!" << endl;
                return 1;
            }

            // if(bcp_bind(dbproc, (BYTE *)ImageFileNumber, 0, (DBINT)-1,
(BYTE *)"", 1, SQLCHAR, 10) == FAIL) {
            //     cout << "bcp_bind for sImageFileNuber FAILED!" << endl;
            //     return 1;
            // }

            // if(bcp_bind(dbproc, (BYTE *)&ImageNumber, 0, (DBINT)-1, (BYTE
*)NULL, 0, SQLINT4, 11) == FAIL) {
            //     cout << "bcp_bind for sImageNumber FAILED!" << endl;
            //     return 1;
            // }

            // Open the recon.dbf file
            fpos_t pos;
            fpRecon = fopen(sFilePath + "recon" + sDropNumber + ".dbf",
"rb");
            fread(sHeaderBuffer, sizeof(char), 1162, fpRecon); // skip the
dbf header
            fgetpos(fpRecon, &pos);
            cout << "Processing Recon file" << endl;
            while(!feof(fpRecon)) {
                fread(sInputBuffer, sizeof(char), 99, fpRecon); // read in
the next record from the dbf
                fgetpos(fpRecon, &pos);

                // Parse the input byte stream
                sOriginalSequence = Hex(sInputBuffer[2]) +
Hex(sInputBuffer[3]) + Hex(sInputBuffer[4])
                                  + Hex(sInputBuffer[5]) +
Hex(sInputBuffer[6]);
                sAccount = "";
                for(int i = 13; i < 23; i++) {
                    sAccount += sInputBuffer[i];
                }

                sSerial = "";
                for(i = 24; i < 34; i++) {
                    sSerial += sInputBuffer[i];
                }

                sTranCode = "";
                for(i = 35; i < 41; i++) {
                    sTranCode += sInputBuffer[i];
                }

                sAmount = "";
                for(i = 42; i < 52; i++) {
                    sAmount += sInputBuffer[i];
                    if(i == 49) {
                        sAmount += ".";
                    }
                }

                sOriginalDate = CString(sInputBuffer[60]) +
CString(sInputBuffer[61]) + "/"
                              + CString(sInputBuffer[62]) +
CString(sInputBuffer[63]) + "/"
                              + CString(sInputBuffer[64]) +
CString(sInputBuffer[65])
                              + CString(sInputBuffer[66]) +
CString(sInputBuffer[67]);
                sImageCode = CString(sInputBuffer[68]) +
CString(sInputBuffer[69]) + CString(sInputBuffer[70]);
                sSequence = Hex(sInputBuffer[77]) + Hex(sInputBuffer[78]) +
Hex(sInputBuffer[79])
                          + Hex(sInputBuffer[80]) + Hex(sInputBuffer[81]) +
Hex(sInputBuffer[82]);

                // Move the data to the db vars for transfer to the server
                strcpy(OriginalSequence, sOriginalSequence);
                strcpy(Account,          sAccount);
                strcpy(Serial,           sSerial);
                strcpy(TranCode,         sTranCode);
                strcpy(Amount,           sAmount);
                strcpy(OriginalDate,     sOriginalDate);
                strcpy(ImageCode,        sImageCode);
                strcpy(Sequence,         sSequence);

                // Send the row to the sql server
                if(bcp_sendrow(dbproc) == FAIL) {
                    cout << "bcp_sendrow FAILED!" << endl;
                    return 1;
                }

                nRowCounter++;
                if(nRowCounter > 9) {
                    // Call bcp_batch to go ahead and "send" the rows we've
created to the sql server.
                    int rv = bcp_batch(dbproc);
                    if(rv = -1) {
                        cout << "Error saving rows to database: " <<
sDatabaseName << endl;
                        return 1;
                    }

                    nRowCounter = 0;
                }
            }

            bcp_done(dbproc); // Let dblib know we're done sending rows so
it can cleanup.



Sat, 08 Mar 2003 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Status Codde = 207 error message when Recordset::Open fails

2. Error Message : Fail to create empty document

3. CListBox: assertion failed error when functions are used in message handler of View-Class (SDI)

4. BUG: Application Fails But Gives No Error Message

5. Error Message : Fail to create empty document

6. cfe: ERROR MESSAGE 8ERROR MESSAGE 103

7. Error:Too many error or message .......

8. Quick question on custom error messages w/ Error() macro

9. An error encountered while running this program - Embedded VB Error Message

10. Error during merge replication :- Error Message-The process could not bulk copy

11. DBlib implementation in C++

12. Compatibility between MFC and sybase's dblib

 

 
Powered by phpBB® Forum Software