You did not indicate which database you are connecting to. In SQL Server 2005 from .NET, you can specify the connection timeout in the connection string as follows:
server=<server>;database=<database>;uid=<user>;password=<password>;Connect Timeout=3
This will try to connect to the server, and if it does not do this in three seconds, it will throw a timeout error.
source share