The Python Oracle

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

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Track title: CC G Dvoks String Quartet No 12 Ame 2

--

Chapters
00:00 Question
01:38 Accepted answer (Score 4)
02:15 Thank you

--

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

Accepted answer links:
[pyodbc.connect]: https://code.google.com/p/pyodbc/wiki/Mo...

--

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)
...