Python将数据插入Sql Server

时间:2014-10-21 12:37:13

标签: python sql pyodbc

努力弄清楚为什么这不起作用。我没有收到任何错误,但它不会写入表格。

import pyodbc
connprod = pyodbc.connect('DRIVER={SQL Server};SERVER=server;DATABASE=master;Trusted_Connection=yes')
cursorprod = connprod.cursor()

conndev = pyodbc.connect('DRIVER={SQL Server};SERVER=server;DATABASE=master;Trusted_Connection=yes')
cursordev = conndev.cursor()

connlocal=pyodbc.connect('DRIVER={SQL Server};SERVER=server;DATABASE=DBA;Trusted_Connection=yes')
cursorlocal = connlocal.cursor()

cursorprod.execute("SELECT Servername = @@servername    ,Date = getdate()   ,wait_type  ,waiting_tasks_count    ,wait_time_ms   ,max_wait_time_ms   ,signal_wait_time_ms FROM sys.dm_os_wait_stats GO")
rows = cursorprod.fetchall()

for row in rows:
    cursorlocal.execute('insert into dba.dbo.dm_os_wait_stats values (?,?,?,?,?,?,?)', row)
    cursorlocal.commit

1 个答案:

答案 0 :(得分:2)

如果您的示例准确无误,则不会调用commit method

cursorlocal.commit()