in reply to MS SQL problem

Can anyone please suggest improvements to this code?

You have your answer to the error, so I'll just mention that you can get rid of all those "or die ..." clauses in your DBI calls if you just set RaiseError during the connect. Plus you will get the added bonus of having error checking during the fetch, which you currently do not have.