title: How to handle TimeOut inside Stored Procedure?
body: <p>I have a stored procedure in which the classic TRY/CATCH error handling does not seem to apply due to a connection time-out.</p>
  
  <p>Environment: MSSQL 2012, PHP 5.4, Win 2008 Server</p>
  
  <p>The stored procedure invokes a new connection to a <strong>remote linked server</strong> and tries to pass the query along. The timeout happens during the connection process (see the code block below) not the query itself. This timeout generates an exception error to ADODB layer which makes the application layer (PHP) script fail. Any idea how to CATCH such timeout ?</p>
  
  <p>Code block:</p>
  
  <pre><code>SET @sql0 = 'SELECT @flag = 1 FROM ' + @server_name + '.[Database].[dbo].[sysobjects] 
  AS sysobjcts WHERE [sysobjcts].[name] =''remote_table'' '
  
  execute sp_executesql @sql0, N'@flag INT OUTPUT', @flag = @flag OUTPUT
  
     -- if table exist
     IF @flag = 1 BEGIN
      ...
  </code></pre>
  
  <p>The above is my simple way to check if the required table exist on the remote server before I try to query it (point of failure). I need to solve it on my end not on the remote linked server.</p>
  
  <p>Thanks for any suggestions.</p>