The Python Oracle

Error: "Cannot perform a backup or restore operation within a transaction." when trying to backup MSSQL database using pyodbc and freetds

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Light Drops

--

Chapters
00:00 Error: &Quot;Cannot Perform A Backup Or Restore Operation Within A Transaction.&Quot; When Trying To
00:58 Accepted Answer Score 4
01:20 Thank you

--

Full question
https://stackoverflow.com/questions/2516...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #sqlserver #pyodbc #freetds

#avk47



ACCEPTED ANSWER

Score 4


autocommit should be specified as a keyword argument to the pyodbc.connect function, it is not part of the ODBC connection string. See the section that starts with:

"Some keywords are used by pyodbc and are not passed to the odbc driver..."


Modify your code to the following:

...
conn = pyodbc.connect('DRIVER=FreeTDS;SERVER=<servername>;PORT=<port>;DATABASE=<database>;UID=<user>;PWD=<password>;TDS_Version=8.0;',
                      autocommit=True)
...