Friday, December 28, 2007

objectdisposedexception - Safe handle has been closed

It's been a while since I've posted, and here is my current issue. I'm writting a call from an webservice to an IBM as/400 storedproc via IBM's "IBM DB2 UDB for iSeries .NET Provider"

It works great! I have a stored procedure on the iSeries system that calls an internal program. I can make the call. However, when my project stops or closes down, I get an ObjectDisposedException, "Safe handle has been closed" I've seen a few posts here and there about it, and finally stumbled across this bit from IBM:

At least they have a patch. Though, I don't know how long it will take our team to get the patch installed, tested and move to production. Well, hopefully it won't take long.

But in any case, at least now I have a path to go down. And according to their records it will work on V5R2M0, V5R3M0, and V5R4M0. We'll see I guess.

If anyone has some other method for working around this error, I'd love to hear about it.


Anonymous said...

Did this work? I'm struggling with the same issue and haven't been able to find any fixes. There is a patch on IBM Web site but it's already installed on our server and it's still erroring out.

If I modify the form's (it's C# Windows application) Dispose method by commenting out the base.Dispose(disposing) line, it doesn't give me any errors. Do you know if it's an acceptable workaround?

Mike said...

From what I can tell, that does work. It's ugly though.

I found that it worked fine in my webservice that was using it. When I created a test app, I had the code in a separate project. I referenced the project in my windows app. When I would run the app stand alone and closed it, or when I debugged the app and close the app (instead of terminating the debug through VS) I'd get the error.

In my project, I had the code in a static class. I'm not sure if that had anything to do with it, or what.

From Microsoft, that's the official workaround. See my other posts on the subject.

blogUserName said...

How do you comment out the base.Dispose line for the form's Dispose method in VB? I'm having the same problem in VB 2008 and would like to use your workaround because unfortunately I am not permitted to update PTF's on our system.

Mike said...

Actually, I found the fix for it. Because I'm new to the 400 coding stuff, I wasn't sure how to update my client access.

If you as400 is running the lates ptf (or some new version), you should be able to install the service pack on your local machine from

That is their ftp site, you may have to change to v5r3m0 if you client access is at the r4 release. But that service pack installs the fixed dll that .net references.

I'm not sure about modifying the base.dispose line for the actual form. My program was a webservice, so i never really saw the error unless iis was reset.

I hope that link works for you.

Anonymous said...

Thanks a million! I had to find one that matched my version but your suggestion worked perfectly.


Anonymous said...

Great !

Thanks Mike for the solution. However, I am afraid your suggestion for the link to the V5R3 fixpack is wrong.

Many thanks