Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9123859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:26:28+00:00 2026-06-17T06:26:28+00:00

I am reading binary data from db and converting it into text by using

  • 0

I am reading binary data from db and converting it into text by using code.

       public String BinaryToText(byte[] data)
       {
         System.Text.Encoding encEncoder = System.Text.ASCIIEncoding.ASCII;

         return encEncoder.GetString(data);
       }

The above procedure is correctly working but when binary file >= 85mb is converted , OutOfMemoryException
is shown.How to convert large binary data into string without error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:26:29+00:00Added an answer on June 17, 2026 at 6:26 am

    I wouldn’t normally expect 85MB too be a problem unless you are low on memory etc. Even x86 can usually handle that without pausing for breath.

    For large amounts of data, the simplest answer is always “don’t hold it all in memory at once”. ADO.NET has a forwards-only API on data-reader that allows successive calls to fetch different parts of a large BLOB:

    using(var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
    {  //                                    ^^ forwards-only mode ^^
      long offset = 0;
      int read;
      byte[] buffer = new byte[8096];
      while ((read = reader.GetBytes(colIndex, offset, buffer, 0, buffer.Length))>0)
      {
         ProcessBytes(buffer, 0, read);
         offset += read;
      }
    }
    

    where ProcessBytes(byte[] buffer, int offset, int count) processes count bytes from buffer, starting at offset. In the case of ASCII, you can probably get away without using an encoding at all; for other encodings, you can use the Encoding.GetDecoder() API to decode a stream of data, although it is a bit messy. These two things together will allow you to handle an arbitrarily large (multi-terabyte if necessary) data-source without having it all in memory at once.

    The next question, then, is: what are you going to do with this data?

    If you do need it all in memory at once, you have no choice but to hold it. You might be able to do something with an iterator block, to return fragments of the string in turn.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I am reading data from a binary file (File.ReadAllBytes), converting this byte array
Currently, I have been reading lists of data from a binary data file programmatically
I'm reading from a binary data file which is written by invoking the following
Using Windows So I'm reading from a binary file a list of unsigned int
I'm getting data from a binary file, reading from file and writing in a
I'm reading binary data (either by network stream or from files) that is predefined
I am reading from serial port using string messaga = _serialPort.ReadLine(); When i Console.WriteLine(messaga);
I've never wandered into reading binary data before. I'm trying to learn now, and
I am reading binary data from one file that specifies intensity values across x
I'm reading binary data from a file, specifically from a zip file. (To know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.