Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>My setup: </p> <ul> <li>Microsoft Windows XP SP3.</li> <li>Microsoft SQL Server 2008 (not R2).</li> <li>CPython 2.7.4.</li> <li>pymssql 2.0.0 (installed with <code>easy_install</code>, IIRC).</li> </ul> <p>I had forgot to create a <code>sa</code> login account, so I remember scavenging a few weeks ago for a way to create it; previously, I was logging in (e.g. with SQL Server Management Studio) with Windows authentication. I followed <a href="https://stackoverflow.com/a/3781737">https://stackoverflow.com/a/3781737</a> to create the <code>sa</code> user account.</p> <p>After that intermediary step, I started Python.</p> <pre><code>import pymssql conn = pymssql.connect(host=r'MACHINE\SQLEXPRESS', user=r'sa', password=r'password', database=r'MYDB') cur = conn.cursor() cur.execute(r'SELECT COUNT(*) FROM mytable') row = cur.fetchone() print row[0] cur.close() conn.close() </code></pre> <p>My guess with your problem is that you should have used <em>raw</em> strings in the connection parameters -- particularly the <code>host</code> parameter, which takes in a backslash.</p> <p>I also tried it with a CentOS 5.8 64-bit machine (pymssql 1.0.2, freetds 0.91). To that effect, I had also created a <code>$HOME/.freetds.conf</code> file with contents as </p> <pre><code>[global] tds version = 10.0 [MACHINE] host = 192.168.1.2 port =1433 tds version = 10.0 encryption = request </code></pre> <p>I forgot where I picked that file's configuration example from.</p> <p>Hope that helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload