In reply to Louis.

If it works intermittently then it seems like your code in general is okay, but maybe you need a setup that hits a specific Workspace server (not load-balanced with Grid) for this particular app.