What is the timeout of a query in SQL Server 2008 I was running a query to delete in batches of a huge table. After say around 3 hrs sometimes 4 hrs I get a message saying


  Invalid object name '#table_name#'


After sometime is there a connection lost or something? What is the cause here?
To answer the specific question: by default there is no timeout while running a query against the database engine. It will happily wait or days for an operation to complete whether the delay is due to the actual statement taking a long time to process or due it being sat waiting for other connections to release relevant locks.

Standard connection libraries like ADO implement timeouts, after which they will tell SQL Server to cancel the current operation and drop the connection.

There are timeout settings governing various processes (login processes, or situations where the database engine itself is asking a remote resource to perform some action, and such) but these do not affect queries given direct to the database engine.

For more specific help you'll need to add further details (the code of your query, the exact error message, perhaps some notes on your structure (is "#tablename# the name of an actual table in your DB?) so we can see if there is something there that would cause the error you have seen.