Skip to content

SQL Server Error 3041 with BACKUP SERVER statement #299

@gordthompson

Description

@gordthompson

Describe the bug

The following known issue with pyodbc also exists with mssql-python

mkleehammer/pyodbc#1431

To reproduce

import mssql_python

mssql_python.setup_logging()
cnxn = mssql_python.connect(
    "SERVER=192.168.0.199;"
    "DATABASE=master;"
    "UID=scott;PWD=tiger^5HHH;"
    "TrustServerCertificate=yes;"
)
cnxn.setautocommit(True)
crsr = cnxn.cursor()
for db_name in ["test", "test2", "test3"]:
    if not crsr.execute("select name from sys.databases where name = ?", db_name).fetchval():
        sql = f"CREATE DATABASE {db_name}"
        print(sql)
        crsr.execute(sql)
crsr.execute(
    "ALTER SERVER CONFIGURATION SET SUSPEND_FOR_SNAPSHOT_BACKUP = ON;"
)
crsr.execute(
    "BACKUP SERVER TO DISK = '/var/opt/mssql/backup/metadata/backup_1.bkm' WITH METADATA_ONLY, FORMAT;"
)

Expected behavior

The backup should succeed, as it does with ADODB (VBScript). For details, see

mkleehammer/pyodbc#1431 (comment)

Further technical details

Python version: 3.13
SQL Server version: SQL Server 2022
Operating system: Windows 11

Additional context
Client-side log:

mssql_python_trace_20251018_090446_10824.log

Server-side errorlog:

errorlog.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions