Given the error message "Incorrect syntax near the keyword 'SET'" , I would speculate that you have a SQL server error. Are you absolutely sure that your SQL statement is correct? You might want to drop a print statement in your code to have the SQL print out prior to the prepare so that you can see if it is being passed on correctly.