Memory could not be allocated

4 posts, 0 answers
  1. Shahbaz
    Shahbaz avatar
    8 posts
    Member since:
    Oct 2014

    Posted 12 Dec 2015 Link to this post

    Hello,

    I'm using 2015 Q1 version of Telerik.dataAccess dll. When i try to fetch multiple BLOB's from database(Oracle) which are more than 100 mb. I face below error. I'm using 8 GB RAM on Windows 7 64 bit machine. Please refer to below code and StackTrace. Sometimes i face the same issue when i try to save it back on database.

     foreach (var dic in scannedLettersDictionary)

      {
          try
          {
              using (FileStream fs = new FileStream(ScannedLettersDirectory + dic.Value.LetterId + ".tiff", FileMode.Create, FileAccess.Write))
              {
                  fs.Write(dic.Value.ScannedLetterContent, 0, dic.Value.ScannedLetterContent.Length);
              }
          }
          catch (Exception ex)
          {
              MessageBox.Show(ex.Message + "  " + dic.Key.ToString());
          }
      }

    Exception.Message:

    Telerik.OpenAccess.RT.sql.SQLException: Memory could not be allocated ---> Oracle.DataAccess.Client.OracleException: Memory could not be allocated
       at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck)
       at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, Object src, Boolean bCheck)
       at Oracle.DataAccess.Client.OracleDataReader.Read()
       at OpenAccessRuntime.Intellitrace.Read(DbDataReader reader, String id)
       at Telerik.OpenAccess.Runtime.Logging.LoggingDbDataReader.Read()
       at Telerik.OpenAccess.RT.Adonet2Generic.Impl.ResultSetImp.next()
       --- End of inner exception stack trace ---
       at Telerik.OpenAccess.RT.Adonet2Generic.Impl.ResultSetImp.next()
       at OpenAccessRuntime.Relational.fetch.FetchResultImp.rsNext()
       at OpenAccessRuntime.Relational.fetch.FetchResultImp.hasNext() 
       
       ========================
       Stack Trace:
       
         at Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e)
       at OpenAccessRuntime.ExceptionWrapper.Throw()
       at OpenAccessRuntime.DataObjects.PCStateMan.handleException(Exception x)
       at OpenAccessRuntime.DataObjects.PCStateMan.getObjectFieldImp(PersistenceCapable pc, FieldMetaData fmd, Object currentValue)
       at OpenAccessRuntime.DataObjects.PCStateMan.GetObjectField(PersistenceCapable pc, Int32 field, Object currentValue)
       at UAEArmedForces.Tarasul3.MelsTLetterDatum.OpenAccessEnhancedGet_scannedLetterContent(MelsTLetterDatum owner)
       at UAEArmedForces.Tarasul3.MelsTLetterDatum.get_ScannedLetterContent() in d:\Projects\Tarasul\Tarasul\Tarasul3Model\MelsTLetterDatum.generated.cs:line 95
       at UAEArmedForces.Tarasul.TarasulSetup.MainForm.ExtractScannedLetterFiles(ConcurrentDictionary`2 scannedLettersDictionary) in d:\Projects\Tarasul\Tarasul\TarasulSetup - Oracle\MainForm.cs:line 7254

     

  2. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 14 Dec 2015 Link to this post

    Hi yousufs,
    Thank you for contacting us.
    This problem looks like there is a problem within the Oracle ODP.NET driver itself. I this forum there was a user complaining about the same problem and it turned out that the driver was the problem. Upgrading to the latest version helped in his case.
    Can you try to use the latest Oracle ODP.NET driver to see if the problem still exists? You can download the driver here. http://www.oracle.com/technetwork/topics/dotnet/index-085163.html

    I hope this information is helpful for you.
    Feel free to ask in case you have any other question.


    Regards,
    Ralph Waldenmaier
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
  3. DevCraft banner
  4. Shahbaz
    Shahbaz avatar
    8 posts
    Member since:
    Oct 2014

    Posted 14 Dec 2015 in reply to Ralph Waldenmaier Link to this post

    Hi Ralph,

     Thank you for your reply. I was able to overcome the issue by changing datatype Byte[ ] in Telerik model to BinaryStream as is recommend here and it works fine. However i'm facing another error now.

    Let me explain what i'm trying to do.

    I'm trying to read blob from database(oracle) and save files onto the system. I want to perform this operation in parallel. Here scannedLettersDictionary is of type ConcurrentDictionary.

    ConcurrentQueue<Exception> exceptions = new ConcurrentQueue<Exception>();
    Parallel.ForEach(scannedLettersDictionary.Where(y => y.Value.ScannedLetterContent != null).Select(x => x), file =>
    {
        try
        {
            using (FileStream stream = new FileStream(ScannedLettersDirectory + file.Value.LetterId + ".tiff", FileMode.Create, FileAccess.Write))
            {
                byte[] bytes = new byte[65536];
                int numBytesToRead = (int)file.Value.ScannedLetterContent.Length;
                int bytesRead = 1;
     
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    while (numBytesToRead > 0 && bytesRead > 0)
                    {
                        bytesRead = file.Value.ScannedLetterContent.Read(bytes, 0, Math.Min(numBytesToRead, bytes.Length));
                        writer.Write(bytes);
                        numBytesToRead -= bytesRead;
                    }
     
                    writer.Flush();
                    writer.Dispose();
                }
            }
        }
        catch (AggregateException ag) { exceptions.Enqueue(ag); }
        catch (Exception e) { exceptions.Enqueue(e); }
    });
     
    if (exceptions.Count > 0)
    {
        foreach (var exp in exceptions)
        {
            LogError(exp, 66, exp.Message, _letterId);
        }
    }

    Issue is with this line. It gives me Access Violation exception.

    bytesRead = file.Value.ScannedLetterContent.Read(bytes, 0, Math.Min(numBytesToRead, bytes.Length));

    Below is the stack trace

    at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeQuery(Nullable`1 commandTimeout)
       at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeQuery(Nullable`1 commandTimeout)
       at OpenAccessRuntime.Relational.sql.SqlDriver.StreamReadData(Connection connection, BinaryStreamData data)
       at OpenAccessRuntime.Relational.RelationalStorageManager.ReadInternal(BinaryStreamData data)
       at OpenAccessRuntime.storagemanager.logging.LoggingStorageManager.ReadInternal(BinaryStreamData data)
       at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.ReadInternal(BinaryStreamData data)
       at OpenAccessRuntime.DataObjects.UnsynchronizedPMProxy.ReadInternal(BinaryStreamData data)
       at OpenAccessRuntime.DataObjects.PCStateMan.ReadInternal(Byte[] buffer, Int32 offset, Int32 count, String fieldName, Int64 internalOffset)
       at Telerik.OpenAccess.BinaryStream.ReadInternal(Byte[] buffer, Int32 offset, Int32 count)
       at Telerik.OpenAccess.BinaryStream.Read(Byte[] buffer, Int32 offset, Int32 count)
       at TSetup.MainForm.<>c__DisplayClass134.<ExportLetterDetails>b__130() in d:\Projects\Tarasul\Tarasul\TarasulSetup - Oracle\MainForm.cs:line 3648

    Appreciate any help. 

     

  5. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 15 Dec 2015 Link to this post

    Hello yousufs,
    First, I am glad that you found a way to get rid of the memory problem.
    To your concurrent approach. Unfortunately, this is a scenario which is not yet supported by Telerik DataAccess. My proposal here would be to obtain the data from your dictionary sequentially.

    Hope this helps.
    Do not hesitate to contact us again in case you have any other question.

    Regards,
    Ralph Waldenmaier
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Back to Top