This may be obvious to you.... but i will state it anyway just incase.
May sure you do not open a database conection and close it every time you run a piece of SQL as this will slow the whole process down dramatically.
I suggest you post the main parts of your code so we can see if there is any weeks spots.