title: pyodbc: How to test whether it's possible to establish connection with SQL server without freezing up
body: <p>I am writing an app with <code>wxPython</code> that incorporates <code>pyodbc</code> to access SQL Server. A user must first establish a VPN connection before they can establish a connection with the SQL server. In cases where a user forgets to establish a VPN connection or is simply not authorized to access a particular server, the app will freeze for up to 60+ seconds before it produces an error message. Often, users will get impatient and force-close the app before the error message pops up. </p>
  
  <p><strong>I wonder if there is a way to test whether it's possible to connect to the server without freezing up.</strong> I thought about using <code>timeout</code>, but it seems that <code>timeout</code> can be used only after I establish a connection</p>
  
  <p>A sample connection string I use is below:</p>
  
  <pre><code>connection = pyodbc.connect(r'DRIVER={SQL Server};SERVER=ServerName;database=DatabaseName;Trusted_Connection=True;unicode_results=True')
  </code></pre>