pyODBC 语句出现在 运行 但不影响 table

pyODBC statement appearing to run but not affecting table

我有以下脚本 运行ning;

from os import getenv
import pyodbc
import os
import sys

cnxn = pyodbc.connect('''
DRIVER={ODBC Driver 13 for SQL Server};SERVER=myServer\SQLEXPRESS;
DATABASE=myTable;UID=myID;PWD=myPassword''')

cursor = cnxn.cursor() #makes connection
cursor.execute("""

            UPDATE ShowroomCal
                SET ShowroomCal.isbusy = 'Yes'
            FROM ShowroomCal
                JOIN calendarbookings on calendarbookings.date=showroomcal.style112 AND calendarbookings.showroom=ShowroomCal.showroom_name
                WHERE CalendarBookings.date = showroomcal.style112 and ShowroomCal.Year='2018'
                """) #runs update statement

row_count = cursor.rowcount #counts afrfected rows
status_msg = "result returned. {} row(s) affected."
print(status_msg.format(row_count)) #prints affected rows

cnxn.close()

笔记本单元格 returns“3 行受影响。”然而 table 在 SQL Express 中查看时并没有改变。

我已经独立 运行 来自 SQL 查询中的服务器管理的语句 Window 它立即更改了可能受影响的三行,所以我知道数据在 table 存在被更改并且声明有效 - 至少从 SQL 的角度来看。

有人能从 Python 的角度发现任何错误吗?

Scratch'N'Purr帮我解答了,非常感谢

如果其他人遇到同样的问题,那就是缺少

cnxn.commit()

后面的语句就是问题所在。我已经对此进行了测试,并且效果很好。