Getting pyssmql to work was pretty easy. (I had less luck using pyodbc.)
sudo apt-get install freetds
sudo pip install pymssql
Create entries for your sqlservers in /etc/freetds/freetds.conf like so:
[dev01]
host = YOUR_SQL_SERVER_HOST
port = 1433
tds version = 8.0
Here's a simple script using it:
import pymssql
import getpass
pwd = getpass.getpass()
conn = pymssql.connect(host='YOUR_SQL_SERVER_HOST',
user='YOUR_DOMAIN\\YOUR_USERNAME', password=pwd)
cur = conn.cursor()
cur.execute('use YOUR_DB')
query = "select top 10 id, name, lastmodifieddate from campaign"
cur.execute(query)
for row in cur:
print "{0}\n{1}\n{2}\n".format(row[0], row[1], row[2])
No comments:
Post a Comment