Timeout expired error when calling executing a SQL statement in Visual Basic on a remote server

I have a SQL statement that executes fine when I run it in SQL Management Studio on the SQL 2008 server.  However, when I run it in my Visual Basic 2008 program on a remote machine, it works part of the time and other times it gets the error "Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding."  I'm guessing that I need to put a timeout value in my VB code, but I don't know how.  I'm using a dataset to get the data.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Do not remember off hand but I think you have to have it do on the server side.
it means you have to optimize your sql query..if possible
You can use "Connect Timeout=30" in the DSN that you create in your VB Code.

More Info here : http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout(VS.71).aspx

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rmunsonusadrugAuthor Commented:
Thanks for all the suggestions.  I had already optimized the query, but it's a very large database and sometimes that server is a little slow.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.