开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜