7
Answers

Insufficient memory to continue the execution of the program.

Hi,
I trying to develop a small program that is able to import images with opendialog and save the images to an SQL database.
Im am currently getting an error that states "Insufficient memory to continue the execution of the program.". This happens when I try to write the data to the database.

I have tried couple of things to resolve this problem. That is, because it was a memory problem I tried running this on two different computers. Ive gone through several tutorials for storing and retrieving images in SQL database. Everything has resulted in the same error.

I convert the image to byte[] and I want to save these byte[] to the database. The database field is a type Image (size 16). The image Im testing is only 9204 bytes.

Im not sure how I can explain this better, because i dont have a clue why I get this error.

Anyone out there that can help me?

kind regards,

Answers (7)

0
Photo of Jan Montano
NA 2k 0 16y
hmm... I'm running ouf of ideas.

Could you post your code for the TableAdapter?
0
tadapt_player is a TableAdapter referencing the sql table or function that I am calling (insert_player)

The following is the code for Insert_player

INSERT INTO [player] ([Image_name], [Image]) VALUES (@image_name, @image)

The function is not recursive. When I debug, the error comes when I runs for the first time.
0
Photo of Jan Montano
NA 2k 0 16y
tadapt_player.Insert_player(image_name ,image)

what data type is tadapt_player?

Where is the code for
tadapt_player.Insert_player(image_name ,image) ?

If ever this is a recursive call, then it will have an endless loop that will lead to memory problems
0
There is one error in the code I posted.

db_interface.Insert actually calls the Insert_player function.
0
Hi,
Thanks for the replies.
The SQL server field image can hold images from 0 to 2147483647 bytes. That is, 100 bytes should not be the problem. Although Komal Patel you have given me possible alternative solution. Maybe not the prettiest .. but a solution :)

The following is the code I use , it shows ...
how I open the picture with opendialog
Convert the image to byte[]
display the picture in a picturebox
and call my database interface class, that inserts the data to the database.

....
openFileDialog1.ShowDialog();  // get image.

Image img = Image.FromFile(this.openFileDialog1.FileName);
                
image_name = "tester.jpg";    //string
image_buffer = imageConverter.imageToByteArray(img); //byte[], this I save to db

pictureBox1.Image = img;

The following is the imageToByte.. function.

public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
  MemoryStream ms = new MemoryStream();
  imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
  byte[] retArray = ms.ToArray();
  ms.Close();
  return retArray;
}


The following is the code for when I try to insert the data into the database.

db_interface is a class the I use for db functions.

db_interface.Insert(image_name, image);

The following is the Insert function

public void Insert_Player(string image_name ,byte[] image )
{
   try
   {
      tadapt_player.Insert_player(image_name ,image);   //This is the line that it crashes.
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
    }
}


0
Photo of Jan Montano
NA 2k 0 16y
hmm... your image size is just 9kb. Memory shouldn't be a problem here.

Could you post some code? Thanks.
0
Photo of Komal Patel
NA 22 0 16y
hi
that might be because of limitation of image field in database...
in that case u can try saving only filename to database and save image to the folder in your project folder using Fileupload.SaveAs() method