Invalid Handle
Posted in 2009
Topics: General Discussion
All, I have run into a rather strange issue with some Informix Functions. We are getting intermittent faults when we call a function that returns a blob. In 20 invokes it fails once or twice, throwing an Argument Exception with the message "Invalid Handle" The function takes 1 parameter as an input and returns 1 row with one column containing the blob data. Any help would be appreciated. Regards MC
Exact version and platform information would help. Art Art S. Kagel Oninit (www.oninit.com) IIUG Board of Directors (art@iiug.org) Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on my employer, Oninit, the IIUG, nor any other organization with which I am associated either explicitly or implicitly. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves. On Wed, Aug 19, 2009 at 5:13 AM, MIKE CADDY <michaelc@hmgcc.gsi.gov.uk>wrote: > All, > > I have run into a rather strange issue with some Informix Functions. > > We are getting intermittent faults when we call a function that returns a > blob. > > In 20 invokes it fails once or twice, throwing an Argument Exception with > the > message "Invalid Handle" > > The function takes 1 parameter as an input and returns 1 row with one > column > containing the blob data. > > Any help would be appreciated. > > Regards > > MC > > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > --0015174bdcc8acf65304717cafcf
We are using IDS 11.10 I'm connecting from a C# application using the Ifx .NET Data Provider.
HELP I've been looking into my error in a little more detail it seems there is not one single source of the error. See bellow for the code being run and some stack traces from the application I Think I've also got a memory leak, when calling into the code aproximalty 600 times I get about 80-100 mb of leaked memory that is not released until the worker processes are restarted. http://localhost:8013/DevStaffPicture.ashx?StaffNumber=12345&MaxWidth=100 System.ArgumentException Invalid Handle at IBM.Data.Informix.IfxConnection.HandleError(IntPtr hHandle, SQL_HANDLE hType, RETCODE retcode) at IBM.Data.Informix.IfxSmartLOB.internalClose() at IBM.Data.Informix.IfxSmartLOB.Close() at IBM.Data.Informix.IfxDataReader.internalGetBlobData(Int32 i) at IBM.Data.Informix.IfxDataReader.GetBytes(Int32 i, Int64 dataIndex, Byte[] buffer, Int32 bufferIndex, Int32 length) at StaffDetails.DevStaffPicture.ProcessRequest(HttpContext context) in C:\\\\WorkSpace\\\\StaffPicTest\\\\DevStaffPicture.ashx.cs:line 49 http://localhost:8013/DevStaffPicture.ashx?StaffNumber=12345&MaxWidth=100 System.ArgumentException Invalid Handle at IBM.Data.Informix.IfxConnection.HandleError(IntPtr hHandle, SQL_HANDLE hType, RETCODE retcode) at IBM.Data.Informix.IfxDataReader.get_FieldCount() at IBM.Data.Informix.IfxDataReader.BuildMetaDataInfo() at IBM.Data.Informix.IfxDataReader.IfxRowSet.InitiateRowWiseBinding() at IBM.Data.Informix.IfxDataReader.IfxRowSet..ctor(IfxDataReader dataReader) at IBM.Data.Informix.IfxDataReader.Read() at StaffDetails.DevStaffPicture.ProcessRequest(HttpContext context) in C:\\\\WorkSpace\\\\StaffPicTest\\\\DevStaffPicture.ashx.cs:line 45 http://localhost:8013/DevStaffPicture.ashx?StaffNumber=12345&MaxWidth=100 System.ArgumentException Invalid Handle at IBM.Data.Informix.IfxConnection.HandleError(IntPtr hHandle, SQL_HANDLE hType, RETCODE retcode) at IBM.Data.Informix.IfxSmartLOB.internalRead(Object buff, Int64 buffOffset, Int64 numBytesToRead, Int64 smartLOBOffset, IfxSmartLOBWhence whence) at IBM.Data.Informix.IfxSmartLOB.internalRead(Object buff) at IBM.Data.Informix.IfxDataReader.internalGetBlobData(Int32 i) at IBM.Data.Informix.IfxDataReader.GetBytes(Int32 i, Int64 dataIndex, Byte[] buffer, Int32 bufferIndex, Int32 length) at StaffDetails.DevStaffPicture.ProcessRequest(HttpContext context) in C:\\\\WorkSpace\\\\StaffPicTest\\\\DevStaffPicture.ashx.cs:line 49 http://localhost:8013/DevStaffPicture.ashx?StaffNumber=12345&MaxWidth=100 System.ArgumentException Invalid Handle at IBM.Data.Informix.IfxConnection.HandleError(IntPtr hHandle, SQL_HANDLE hType, RETCODE retcode) at IBM.Data.Informix.IfxSmartLOB.get_internalPosition() at IBM.Data.Informix.IfxSmartLOB.internalRead(Object buff) at IBM.Data.Informix.IfxDataReader.internalGetBlobData(Int32 i) at IBM.Data.Informix.IfxDataReader.GetBytes(Int32 i, Int64 dataIndex, Byte[] buffer, Int32 bufferIndex, Int32 length) at StaffDetails.DevStaffPicture.ProcessRequest(HttpContext context) in C:\\\\WorkSpace\\\\StaffPicTest\\\\DevStaffPicture.ashx.cs:line 49 http://localhost:8013/DevStaffPicture.ashx?StaffNumber=12345&MaxWidth=100 System.AccessViolationException Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at IBM.Data.Common.UnsafeNativeMethods.Ifx32.SQLFreeStmt(IntPtr StatementHandle, Int16 Option) at IBM.Data.Informix.IfxDataReader.Dispose(Boolean disposing) at IBM.Data.Informix.IfxDataReader.System.IDisposable.Dispose() at IBM.Data.Informix.IfxCommand.ExecuteScalar() at StaffDetails.StaffPicture.ProcessRequest(HttpContext context) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.I ExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) Source using System; using System.Configuration; using System.Data; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Web; using IBM.Data.Informix; namespace StaffDetails { /// <summary> /// Staff Picture Web Handler to return image from Informix DB /// </summary> public class DevStaffPicture : IHttpHandler { /// <summary> /// Process the Request - Get the blob from the DB, resize if required and render /// </summary> /// <param name="context">the HttpContext</param> public void ProcessRequest(HttpContext context) { //Get Execution Parameters int StaffNum = ValidateNumberQueryStringParameter(context.Request); int MaxHeight = ValidateNumberQueryStringParameter(context.Request); int MaxWidth = ValidateNumberQueryStringParameter(context.Request); //Set Jpeg Response content type context.Response.ContentType = "image/jpeg"; context.Response.Buffer = false; byte[] staffPic = null; try { using (IfxConnection InformixConnection = new IfxConnection(ConfigurationManager.ConnectionStrings.ConnectionString)) { InformixConnection.Open(); using (IfxCommand StaffPictureConnnection = new IfxCommand("get_staff_photo", InformixConnection)) { StaffPictureConnnection.CommandType = CommandType.StoredProcedure; StaffPictureConnnection.Parameters.Add("staffnumber", StaffNum); IfxDataReader staffPicReader = StaffPictureConnnection.ExecuteReader(); if (staffPicReader.Read()) <<<<<< Line 45 >>>>>>> { if (!staffPicReader.IsDBNull(0)) { int BlobSize = (int)staffPicReader.GetBytes(0, 0, null, 0, 0); <<<<<< Line 49 >>>>>>> staffPic = new byteBlobSize; staffPicReader.GetBytes(0, 0, staffPic, 0, BlobSize); } } //Also tested with //staffPic = StaffPictureConnnection.ExecuteScalar() as byte[]; //We might get null if we feed the DB an invalid Staff number } } } catch (IfxException ex) { SendErrorEmail("Staff Pic Ifx Exception", ex.Message + "\\\\r\\ " + ex.StackTrace, "PicTest", ConfigurationManager.AppSettings, ConfigurationManager.AppSettings, ConfigurationManager.AppSettings); } catch (Exception ex) { SendErrorEmail("Staff Pic Exception", ex.GetType().ToString() + "\\\\r\\ " + ex.Message + "\\\\r\\ " + ex.StackTrace, "PicTest", ConfigurationManager.AppSettings, ConfigurationManager.AppSettings, ConfigurationManager.AppSettings); } if (staffPic == null) { //Load a "Invalid User" Image staffPic = File.ReadAllBytes(context.Server.MapPath("~/images/noPhoto.jpg")); } //Check If we have been asked to resize if ((MaxHeight > 0) || (MaxWidth > 0)) { staffPic = ResizeImage(staffPic, MaxHeight, MaxWidth); } //Write it out to the user context.Response.OutputStream.Write(staffPic, 0, staffPic.Length); context.Response.End(); staffPic = null; }