AnsweredAssumed Answered

Errors \ How-to - PYODBC to create SQL Express Backup

Question asked by bfricke on Sep 28, 2015
Latest reply on Sep 30, 2015 by bfricke

Hello

I am trying to make a SQL Express .BAK file of an SDE using the PYODBC in pywin32.

I have the sample code (below), but am not too sure if I have it set-up correctly.  Could anyone explain the parameters in an example?  Specifically the connection parameters.

When I run the script that I have so far, I am getting an error about SQL.    Any help will be appreciated.

Ben

Error: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (17) (SQLDriverConnect); [01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (53)')

 

Sample Code that I used from another post:

  1. import pyodbc 
  2.  
  3. conn = pyodbc.connect('DRIVER={SQL Server};SERVER= <server name>;UID=sa;PWD=sa;Trusted_Connection=yes', autocommit=True
  4. backup_path = 'C:\\temp\\' 
  5. db = "VECTOR" 
  6.  
  7. def backup_db(conn, db, backup_path): 
  8.   cur = conn.cursor() 
  9.   try: 
  10.     cur.execute('BACKUP DATABASE ? TO DISK=?', [db, backup_path + db + r'.bak']) 
  11.     while cur.nextset():  
  12.       pass 
  13.     cur.close() 
  14.   except: 
  15.     print 'Unable to backup: ' + db 
  16.  
  17. backup_db(conn, db, backup_path) 
  18.  
  19. conn.close()

Outcomes