if you do table.close and after that you do a "commit", it's not more than normal you get this error since the table you try to work on is closed. The table.close statement should be the last you call.
As for your dbImage problem: the current implementation writes the type of image as string in the blob field. That breaks the functionality: if you load the image from blob in a stream and the image was saved in the stream by a dbimage, you get the JPEG error. The other way around: if you put a image in a blob field in code without the dbImage, the type marker is not set and that also destroys the working.
It's an old discussion, the only way to use image blobs is to avoid the dbimage. I have filed a changer request but don't have SVN so I doubt if my proposal will ever be implemented.