title: Connect to SQL Server instance using pymssql
body: <p>I'm attempting to connect to a SQL Server instance from a Windows box using pymssql (version 2.0.0b1-dev-20111019 with Python 2.7.1). I've tried the most basic approach from the console:</p>
  <pre><code>import pymssql
  c = pymssql.connect(host = r'servername\instance',
                      user = 'username',
                      password = 'userpassword')
  </code></pre>
  <p>In response to this, I get the very helpful error: <code>InterfaceError: Connection to the database failed for an unknown reason.</code></p>
  <p>I am reasonably confident that the connection information is correct, as it works when I use adodbapi, with the following commands:</p>
  <pre><code>import adodbapi
  c = adodbapi.connect(r'Provider=sqloledb;Data Source=servername\instance;User ID=username;password=userpassword;'
  c.close
  </code></pre>
  <p>I've tried adding the port number to the host parameter, with the same result. Does anyone have a suggestion on how to go about resolving this issue?</p>
  <hr />
  <p>Incidentally, I've read the responses at &quot;<a href="http://stackoverflow.com/questions/4150524/unable-to-connect-to-sql-server-via-pymssql">Unable to connect to SQL Server via pymssql</a>&quot;. The OP eventually resolved his issue by correctly configuring FreeTDS, which, from what I can tell, is not used by pymssql on Windows.</p>
  <hr />
  <p>Based on @cha0site's recommendation, I have tried using just the hostname, rather than the hostname and instance. This resulted in the same error, but it seemed to take longer to generate the error (though the traceback still indicates the same line). The reason I have been specifying the instance is that I was not able to connect using SSMS unless I specified the instance, so I assumed that it would be necessary for other connections.</p>
  <hr />
  <p>I've now also tried <code>pymssql.connect(host='servername', user='username', password='userpassword', database='instance')</code> with the same result (based on @Sid's comment). Based on the <a href="http://code.google.com/p/pymssql/wiki/PymssqlModuleReference" rel="nofollow noreferrer">pymssql documentation</a>, I believe the <code>database</code> parameter is used to specify the initial database that the user is to be connected to, rather than the instance.</p>
  <p>Just to clarify, &quot;instance&quot; is the name provided during installation of SQL Server, not a database within that installation. It occurs to me that it's possible that pymssql does not support this notation, so I will look into re-configuring the SQL Server instance so that it is not required.</p>
  <hr />
  <p>I've now re-installed SQL Server as a default instance, rather than a named instance, which allows me to connect without specifying the instance name. <code>adodbapi</code> still works (without <code>/instance</code>), but <code>pymssql</code> still returns the same error. I've also removed and re-installed <code>pymssql</code> from a freshly downloaded archive (still the same version).</p>