I'm writing Python to backup MS SQL database to a different server. When I put the //remoteServer/share/filename into command, I get:
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot open backup device 'E:\Data\MSSQL15.MSSQLSERVER\MSSQL\Backup\\REMOTESERVER\SHARE\foobar.bak'.Operating system error 3(The system cannot find the path specified.). (3201) (SQLExecDirectW);[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]BACKUP DATABASE is terminating abnormally. (3013)")
Python 3.10.13, pyodbc 5.0.1 on Windows 10
SQLServer SQL Server Express 15.0.2104
Remote server Windows Server 2019. Share permissions include host name for SQL Server
When I remove //remoteserver/share/ from command leavingbackup_command = """BACKUP DATABASE BaseData TO DISK = 'foobar.bak';""" it runs,but the file ends up in default backup location(duh). Also, BACKUP DATABASE BaseData TO DISK = '\\REMOTESERVER\SHARE\foobar.bak' works when ran from SSMS while connected to SQLServer. How do I get it to stop adding default backup path?
import pyodbc# Connection parametersserver = 'SQLServer'database = 'BaseData'username = 'User'password = 'Password'# Create a connection objectconn = pyodbc.connect('DRIVER={SQL Server};SERVER='+ server +';DATABASE='+ database +';UID='+ username +';PWD='+ password)conn.autocommit = True# Create a cursor objectcursor = conn.cursor()# ---------------------------------------------------------------------------------------------------------------------------------# Backup command backup_command = """BACKUP DATABASE BaseData TO DISK = '//REMOTESERVER/SHARE/foobar.bak';"""# Execute the backup commandcursor.execute(backup_command)#process return so that does not errorwhile (cursor.nextset()): passSame situation as this post except error different.