Lock time out..Connection time out


I have a program that runs a query against a MS SQL Server database and it
takes quite amount of time to finish. So far I have never had it completed
because program generates an error saying

"Lock time out..Connection time out"

How can I prevent this and have my query computed ?