If, as you cliam this works command line then there is something wrong with your code. Do check that each operation is successful, and if not display (or otherwise alert you) to the fact an error has occured? If you post your code (remove sensitive data, passwords etc) someone will try and help you. Please read