1

I am facing challenge in updating Database using pypyodbc module. Not getting any error, code is successfully executed; but SQL-Server DB is not updated. Fetching from DB is happening.

Please check:

connection = pypyodbc.connect('Driver={SQL SERVER};Server=ser;Database=db;uid=uname;pwd=pass')

cursor=connection.cursor()

cursor.execute("declare @today as date;set @today = convert(varchar,getdate(),101);Update dbo.Credentials_Mst Set Password='qwerty',lastModifiedOn=@today,ModifiedBy='abcd' where Username='abc';")
DhruvJoshi
  • 17,041
  • 6
  • 41
  • 60

1 Answers1

2

You need to commit your changes. Add this line:

connection.commit()

After you do cursor.execute(...).

If you don't commit before closing the connection, you will lose all of your changes.

Remolten
  • 2,614
  • 2
  • 25
  • 29