LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

SQL Toolkit DBFetchRandom causes GPF when records exceed 10

I'm using CVI2013 SP1 and the SQL Toolkit 2.2 on a Win7 machine. 

Basically what  I'm doing is searching the database for records matching a tag and inserting those in a listbox.  This function works as expected when there are just a few records.  However, when the number of records is 11 I get a General Protection Fault when calling DBFetchRandom().  This happens in both Release and Debug modes.  Is there some limitation on the number of records that DBFetchRandom can access?

 

The error occurs at the first call of DBFetchRandom:

...

else if ( 1 < iNumRecs )
{         
            iReturn = DBFetchRandom( iHandleSQLStatementADS, iNumRecs ) ; // Go to the last item

...

int CVICALLBACK SearchForADs (int panel, int control, int event,
                              void *callbackData, int eventData1, int eventData2)
{      
   int iTargetADS = 0 ;
   char caSQLStatement[128] ;
   char caTimestamp[23] ;
   int iNumRecs = 0 ;
   int iCounter ;
   int iReturn = 0 ;
   
   switch (event)
   {
      case EVENT_COMMIT:
         // Get the serial number of the IMU whose data to show
         GetCtrlVal( panel, PANEL_ADS_SERIAL, &iTargetADS ) ;
         
         // Clear the multiple items list boxes
         DeleteListItem( panel, PANEL_ADS_LIST_DATES_ADS, 0, -1 ) ;
         
         // Clear data fields, keep the serial number
         v_ClearDataADS ( panel ) ;
         SetCtrlVal( panel, PANEL_ADS_SERIAL, iTargetADS ) ;
         
         // Establish connection with the database
         iHandleDatabaseConnectionADS = DBConnect ("DSN=ASIDatabase; UID=IMUATPProgram; PWD=hic3zerh");
         
         if ( 0 >= iHandleDatabaseConnectionADS )
         {
            MessagePopup( "Connection Error", "Couldn't connect to database" ) ;    
         }
         else
         {
            // Allow bidirectional search
            DBAllowFetchAnyDirection ( iHandleDatabaseConnectionADS, 1) ;
            
            // Get a handle to the SQL statement that looks up the selected IMU and get a count of the items that statement returns
            Fmt( caSQLStatement, "SELECT * FROM ADS_ATP_Table WHERE SerialNum = %i\0", iTargetADS ) ;
            iHandleSQLStatementADS = DBActivateSQL ( iHandleDatabaseConnectionADS, caSQLStatement ) ; 
            if ( iHandleSQLStatementADS > 0 ) 
            {
               iNumRecs = DBNumberOfRecords ( iHandleSQLStatementADS ) ;
            }
         }
         
         if ( 0 >= iNumRecs )
         {
            MessagePopup( "No Records!", "No ADS records were found for that serial number. " ) ;
            v_ClearDataADS( panel ) ;
         }
         else if ( 1 == iNumRecs )
         {
            // Update data display
            i_UpdateDataADS( panel ) ;
         }
         else if ( 1 < iNumRecs )
         {         
            iReturn = DBFetchRandom( iHandleSQLStatementADS, iNumRecs ) ; // Go to the last item
            
            SetCtrlAttribute ( panel, PANEL_ADS_LIST_DATES_ADS, ATTR_DIMMED, 0 ) ;
            
            // put timestamps into PANEL_ADS_LIST_DATES_ADS, starting with the latest
            for ( iCounter = iNumRecs; iCounter > 0; iCounter-- )
            {
               DBGetColCharBuffer( iHandleSQLStatementADS, 5, caTimestamp, 23, "" ) ;
               InsertListItem ( panel, PANEL_ADS_LIST_DATES_ADS, -1 , caTimestamp, iCounter ) ;
               DBFetchPrev( iHandleSQLStatementADS ) ;   
            }
            iReturn = DBFetchRandom( iHandleSQLStatementADS, iNumRecs ) ; // Go to the last item
         }
         else 
         {
         }

         break;
   }
   return iReturn ;
0 Kudos
Message 1 of 2
(2,964 Views)

I don't see a good reason why you wouldn't be able to get more than 10.  When you recieve the error, what is the value of iNumRecs?  Also, if you simply the code to just a DBFetchRandom() call with the recordNumber explicitly set to above 10, does it still give the GPF?

0 Kudos
Message 2 of 2
(2,931 Views)