是这种情况。我想使用pyodbc备份MSSQL数据库。当我在命令数据库中执行以下命令时,可以很好地备份它:
cursor.execute(
r"BACKUP DATABASE [MYDBNAME] TO DISK = N'C:\Backups\mybackup.bak' WITH NOFORMAT, NOINIT, NAME = N'mybackup.bak', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 10"
)
但是当我在变量中声明该语句并执行时,说:
backupStatement = r"BACKUP DATABASE [MYDBNAME] TO DISK = N'C:\Backups\mybackup.bak' WITH NOFORMAT, NOINIT, NAME = N'mybackup.bak', SKIP, NOREWIND, NOUNLOAD, COMPRESSION, STATS = 10"
curson.execute(backupStatement)
我收到以下错误消息:
TypeError: The first argument to execute must be a string or unicode query.
我在这里想念什么?