Error 5126 (ERR_DATABASE_NO_MORE_DATA) when trying to read data from a table.

 

I have a table like this:

int Read_LastTrend(string UsedSymbol, string sCol)
{
   int Ret = 0;
   ResetLastError();
   
   //Create or open the database in the common terminal folder
   string filename = Filename(SCANNER_NAME, true);
   int db = DbOpen(filename, __FUNCTION__);
   if (db == INVALID_HANDLE)
   {
      Print("DB: ", filename, " open failed with code ", GetLastError());
      return 0;
   }
   
   //Create a query and get a handle for it
   string SQL = StringFormat("SELECT %s FROM LastTrend WHERE UsedSymbol='%s';", sCol, UsedSymbol);
   int request = DatabasePrepare(db, SQL);
   if (request == INVALID_HANDLE)
   {
      printf("%s request failed with code %d", filename, GetLastError());
      DatabaseClose(db);
      return 0;
   }
   else
   {
      if (DatabaseRead(request))
	  DatabaseColumnInteger(request, 0, Ret);
      else
	  printf("Lỗi DatabaseRead(request) " + GetLastError() + " | " + SQL);

      //Remove the query after use
      DatabaseFinalize(request);
   }
   
   //Close the database
   DatabaseClose(db);
   
   return Ret;
}

I used the above function to read information from the table. Occasionally, an error with error code 5126 (ERR_DATABASE_NO_MORE_DATA) occurs. Sometimes the data is retrieved, sometimes an error occurs. The table above shows 6 currency pairs, but the USDCAD pair is showing an error; the other 5 pairs are working normally.

I am using version 5.0 build 5660.

Could you please help me fix this problem? Thank you very much.