|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Generic error in GDI+..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 Why are you loading them as images first? I would think you'd
load the binary file as is with the BinaryReader and save the byte array and not bother with GDI+ at all until you get ready to render the image. -- 2005 Microsoft MVP C# Robbe Morris http://www.robbemorris.com http://www.masterado.net/home/listings.aspx Show quote "HarlanM" <Harl***@discussions.microsoft.com> wrote in message news:D19D45AA-6B9A-4FBB-9765-6AA907AF7C7D@microsoft.com... > 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 Good point. I didn't know I could do it that way. The only example I could
find for writing images to a binary data field was done through an image. I will look into the BinaryReader. I do load them as images for display as a function of another part of the application, but maybe I don't need to go through an image in the save process. Thanks very much for pointing me the right way. Harlan Marshall Show quote "Robbe Morris [C# MVP]" wrote: > Why are you loading them as images first? I would think you'd > load the binary file as is with the BinaryReader and save the byte > array and not bother with GDI+ at all until you get ready > to render the image. > > -- > 2005 Microsoft MVP C# > Robbe Morris > http://www.robbemorris.com > http://www.masterado.net/home/listings.aspx > > > > "HarlanM" <Harl***@discussions.microsoft.com> wrote in message > news:D19D45AA-6B9A-4FBB-9765-6AA907AF7C7D@microsoft.com... > > 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 > > > |
|||||||||||||||||||||||