G
Guest
I'm loading thousands of images into a SQL Server 2000 database. I have a
..NET windows application that I'm working on written in C# that retrieves the
fileinfo of the directory and then loads all of the images into an image
field in the database. The problem I'm having is that I get an unhandled
exception after loading about 900 images that says "A generic error occured
in GDI+". I've determined that it has something to do with loading the
images. If I do everything but actually retrieve and load the images it runs
fine.
Here is the code that retrieves and loads the images to the database:
string strSQL = @"INSERT INTO page(page_image) VALUES (@page_image)";
SqlCommand sqlCommand_page = new SqlCommand(strSQL, sqlConnection_DocImage);
SqlParameterCollection pc_page = sqlCommand_page.Parameters;
pc_page.Add(new System.Data.SqlClient.SqlParameter("@page_image",
System.Data.SqlDbType.VarBinary, 2147483647, "page_image"));
Image img;
sqlConnection_DocImage.Open();
foreach(FileInfo row in jpgFileInfo)
{
using(MemoryStream imageMS = new MemoryStream())
{
img = Image.FromFile(row["fullname"].ToString());
img.Save(imageMS, ImageFormat.Jpeg);
pc_page["@page_image"].Value = imageMS.ToArray();
}
sqlCommand_page.ExecuteNonQuery();
}
sqlConnection_DocImage.Close();
The error message gives me no clue to diagnose what's happening. It sounds
like a resource isn't being disposed of.
Thanks in advance for any help.
HArlan Marshall
..NET windows application that I'm working on written in C# that retrieves the
fileinfo of the directory and then loads all of the images into an image
field in the database. The problem I'm having is that I get an unhandled
exception after loading about 900 images that says "A generic error occured
in GDI+". I've determined that it has something to do with loading the
images. If I do everything but actually retrieve and load the images it runs
fine.
Here is the code that retrieves and loads the images to the database:
string strSQL = @"INSERT INTO page(page_image) VALUES (@page_image)";
SqlCommand sqlCommand_page = new SqlCommand(strSQL, sqlConnection_DocImage);
SqlParameterCollection pc_page = sqlCommand_page.Parameters;
pc_page.Add(new System.Data.SqlClient.SqlParameter("@page_image",
System.Data.SqlDbType.VarBinary, 2147483647, "page_image"));
Image img;
sqlConnection_DocImage.Open();
foreach(FileInfo row in jpgFileInfo)
{
using(MemoryStream imageMS = new MemoryStream())
{
img = Image.FromFile(row["fullname"].ToString());
img.Save(imageMS, ImageFormat.Jpeg);
pc_page["@page_image"].Value = imageMS.ToArray();
}
sqlCommand_page.ExecuteNonQuery();
}
sqlConnection_DocImage.Close();
The error message gives me no clue to diagnose what's happening. It sounds
like a resource isn't being disposed of.
Thanks in advance for any help.
HArlan Marshall