python3.7 sqlserver to insert data using pymssql

import  pymssql
conn = pymssql.connect(host='szs',server='SZS\SQLEXPRESS',port='51091', user='python', password='python', database='python',charset='utf8',autocommit=True)
cur = conn.cursor()
sql = "insert into [novals] values ('python','python','python','python');COMMIT "
try:
cur.execute(sql)
except:
conn.rollback()
cur.close()
conn.close()
 

Insert data need to add the following sql statement COMMIT, while the need to set autocommit = True at the junction, if I tried not insert unsuccessful.

Before checked saw a lot of people say that using conn.commit () at (sql) behind cur.execute, but I tried many times without success, until you see https://blog.csdn.net/markchiu/article/details / 50833504 , try holding the attitude, turned out to be successful, it is silent! Hereby record

Guess you like

Origin www.cnblogs.com/xifengmo/p/10994712.html