Cron job to connect to sql server and run a sproc using python
I want to learn python, and my task is the run a sql server 2008 stored procedure via a cron job.
Can someone step throug开发者_Python百科h a script for me in python?
I am assuming you mean Microsoft's SQL server...
#! /usr/bin/python
import pymssql
con = pymssql.connect (host='xxxxx',user='xxxx',
password='xxxxx',database='xxxxx')
cur = con.cursor()
query = "DECLARE @id INT; EXECUTE sp_GetUserID; SELECT @id;"
cur.execute(query)
outputparameter = cur.fetchall()
con.commit()
con.close()
Taken from http://coding.derkeiler.com/Archive/Python/comp.lang.python/2008-10/msg02620.html (copyright retained)
Put that in a script and run it from cron...
Check this question too.
精彩评论