Skip to content

Allow a caller-supplied Application Name (APP) instead of hardcoding "MSSQL-Python" #649

Description

@sdebruyn

Summary

mssql_python does not let an application set its own Application Name on a connection. The driver reserves the APP connection-string parameter and always overrides it with the literal "MSSQL-Python", so every connection reports program_name = MSSQL-Python in sys.dm_exec_sessions and in the Fabric / SQL Server query history.

Details (as of mssql-python 1.9.0)

  • connection_string_parser.py removes APP from the user-supplied connection string (it is in _RESERVED_PARAMETERS).
  • connection.py raises ValueError if APP is passed via connect() kwargs (reserved parameter).
  • connection.py then unconditionally sets, after processing kwargs:
    # Step 4: Add Driver and APP (always controlled by the driver).
    normalized_params["Driver"] = "ODBC Driver 18 for SQL Server"
    normalized_params["APP"] = "MSSQL-Python"

So there is currently no supported way (connection string or kwarg) for a caller to set the application name.

Why this matters

  • Tools and services built on mssql_python cannot identify themselves in sys.dm_exec_sessions.program_name or in query history; everything is attributed to MSSQL-Python, which makes per-application monitoring, auditing and troubleshooting much harder.
  • Microsoft Fabric (and SQL Server) support workload classification / routing by Application Name. With the name pinned to MSSQL-Python, callers cannot route their workloads to a custom classifier.
  • The ODBC Driver itself, and pyodbc, both honour an APP= value supplied by the caller.

Request

Let callers set the application name, while keeping MSSQL-Python as the default when none is supplied. For example:

  • honour an APP=... value present in the connection string, or
  • accept an application_name="..." (or app="...") keyword on connect() / Connection(...),

falling back to "MSSQL-Python" only when the caller did not provide one.

Repro

import mssql_python
conn = mssql_python.connect("Server=...;Database=...;Encrypt=yes;APP=MyApp")
cur = conn.cursor()
cur.execute("SELECT program_name FROM sys.dm_exec_sessions WHERE session_id = @@SPID")
print(cur.fetchone())  # -> ('MSSQL-Python',)  (expected: 'MyApp')

Thanks for the driver, otherwise it has been a pleasure to build on.

Metadata

Metadata

Assignees

Labels

area: connectivity-authConnection lifecycle, Entra/SP/NTLM auth, tokens, TLS, conn-string parsing, Fabric endpoints.duplicateThis issue or pull request already existsenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions