My setup:
- Microsoft Windows XP SP3.
- Microsoft SQL Server 2008 (not R2).
- CPython 2.7.4.
- pymssql 2.0.0 (installed with
easy_install
, IIRC).
I had forgot to create a sa
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 https://stackoverflow.com/a/3781737 to create the sa
user account.
After that intermediary step, I started Python.
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()
My guess with your problem is that you should have used raw strings in the connection parameters -- particularly the host
parameter, which takes in a backslash.
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 $HOME/.freetds.conf
file with contents as
[global]
tds version = 10.0
[MACHINE]
host = 192.168.1.2
port =1433
tds version = 10.0
encryption = request
I forgot where I picked that file's configuration example from.
Hope that helps.