title: Error: "Cannot perform a backup or restore operation within a transaction." when trying to backup MSSQL database using pyodbc and freetds
body: <p>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:</p>
  
  <p>Python 2.7.6, pyodbc 3.0.7, freetds 0.91-2, Centos 6.5</p>
  
  <p>The code I'm running are as follows (with names and passwords etc removed):</p>
  
  <pre><code>import pyodbc
  
  conn = pyodbc.connect('DRIVER=FreeTDS;SERVER=&lt;servername&gt;;PORT=&lt;port&gt;;DATABASE=&lt;database&gt;;UID=&lt;user&gt;;PWD=&lt;password&gt;;TDS_Version=8.0;Autocommit=True;')
  sql = "exec dbo.backupStashDB"
  cursor=conn.cursor().execute(sql)
  while cursor.nextset():
     pass
  conn.close()
  </code></pre>
  
  <p>The error message I get is:</p>
  
  <pre><code>exec dbo.backupnameDB
  Traceback (most recent call last):
    File "soph_stash_db_bkp.py", line 6, in &lt;module&gt;
  conn.execute(sql)
  pyodbc.ProgrammingError: ('42000', '[42000] [FreeTDS][SQL Server]Cannot perform a backup or restore operation within a transaction. (3021) (SQLExecDirectW)')
  </code></pre>
  
  <p>I get the same message whether or not I run the command 'manually' or via a stored procedure as in this code example.</p>
  
  <p>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.</p>
  
  <p>Does anyone have any helpful insights to share on this one?</p>
  
  <p>Thanks in advance, Mike</p>