Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I'm getting out of memory exception while converting byte array into a string. Initially I've stored content of a file(338 MB) into DataBase in varbinay format , after reading the content from DataBase I'm conveting that Byte array into string wher I'm getting the error .
var val = cmd.ExecuteScalar();//Getting form DataBase
System.Text.Encoding enc = System.Text.Encoding.ASCII;
string myString = enc.GetString((byte[])val);//Converting into String

Please someone tell me a solution.

Thanks & Regards,
Ramana
Posted
Updated 16-Jun-16 23:06pm
v2
Comments
Sergey Alexandrovich Kryukov 9-May-11 3:33am    
Exception details, please, stack, inner, report code line...
--SA

You will need to break up the string into chunks and process the chunks individually. There is a good example of how to do this Here[^].

Hope this helps
 
Share this answer
 
The first thing I would try is do the same with a SMALL file.

If this works fine, it's pretty sure that the amount of your data 338 MB is to big. You will have to read and convert it in pieces (maybe 100k per read/convert ...).
 
Share this answer
 
v2
Hi, I'm having the same problem just now and I got to this question when I try googling for solution. Fortunately, I came with the solution here[^].
-ps:Consider giving final modifier in class declaration.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900