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,
Loading
Jan MontanoPosted Jan 12, 2009, 10:13 PM
Could you post your code for the TableAdapter?
Birgir GudmundssonPosted Jan 9, 2009, 10:22 AM
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.
Jan MontanoPosted Jan 9, 2009, 3:19 AM
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
Birgir GudmundssonPosted Jan 9, 2009, 2:14 AM
db_interface.Insert actually calls the Insert_player function.
Birgir GudmundssonPosted Jan 9, 2009, 2:12 AM
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());
}
}
Jan MontanoPosted Jan 9, 2009, 12:44 AM
Could you post some code? Thanks.
Komal PatelPosted Jan 9, 2009, 12:07 AM
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