0

Struggling to figure out why this isnt working. I don't get any errors but it will not write to the table.

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 Answer 1

2

If your example is accurate, you're not calling the commit method:

cursorlocal.commit()
Sign up to request clarification or add additional context in comments.

1 Comment

commit is not the same as commit(). You are not calling the method. If you remove the indent the commit will be called after all execute() calls. It just depends on what you want to do.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.