I'm currently running into some problems when I'm trying to backup a MSSQL database from a Linux host using pyodbc and freetds. The versions are as follows:
Python 2.7.6, pyodbc 3.0.7, freetds 0.91-2, Centos 6.5
The code I'm running are as follows (with names and passwords etc removed):
import pyodbc
conn = pyodbc.connect('DRIVER=FreeTDS;SERVER=<servername>;PORT=<port>;DATABASE=<database>;UID=<user>;PWD=<password>;TDS_Version=8.0;Autocommit=True;')
sql = "exec dbo.backupStashDB"
cursor=conn.cursor().execute(sql)
while cursor.nextset():
pass
conn.close()
The error message I get is:
exec dbo.backupnameDB
Traceback (most recent call last):
File "soph_stash_db_bkp.py", line 6, in <module>
conn.execute(sql)
pyodbc.ProgrammingError: ('42000', '[42000] [FreeTDS][SQL Server]Cannot perform a backup or restore operation within a transaction. (3021) (SQLExecDirectW)')
I get the same message whether or not I run the command 'manually' or via a stored procedure as in this code example.
I did some googling and found references to adding 'Autocommit=True' would resolve this problem but that doesn't seem to make any difference at all.
Does anyone have any helpful insights to share on this one?
Thanks in advance, Mike