-
Notifications
You must be signed in to change notification settings - Fork 41
Description
Feature Request: Support setting Application Name or APP in connection string
Description
Currently, the mssql-python driver does not allow users to specify the application name via the connection string. Attempting to set the APP or Application Name parameter fails with parsing errors.
Allowing developers to set the application name is a critical feature for database observability, troubleshooting, and workload management. It allows DBAs to filter Extended Events, view program_name in sys.dm_exec_sessions, and trace queries back to specific applications or scripts.
Adding this capability would bring mssql-python into feature parity with Microsoft's other official SQL Server drivers (ADO.NET, ODBC, OLE DB, JDBC, Go, etc.).
Steps to Reproduce
When passing standard application name parameters in the connection string using mssql-python v1.3.0, the driver rejects them.
Test 1: Using APP=
import mssql_python as mssql
conn_str = "server=localhost;database=master;Trusted_Connection=yes;APP=MyPythonApp;TrustServerCertificate=yes"
conn = mssql.connect(conn_str)Error Output:
Connection string parsing failed:
Reserved keyword 'app' is controlled by the driver and cannot be specified by the user
Test 2: Using Application Name=
import mssql_python as mssql
conn_str = "server=localhost;database=master;Trusted_Connection=yes;Application Name=MyPythonApp;TrustServerCertificate=yes"
conn = mssql.connect(conn_str)Error Output:
Connection string parsing failed:
Unknown keyword 'application name' is not recognized
Expected Behavior
The driver should accept either APP=MyApp or Application Name=MyApp (or both, for backwards compatibility with ODBC/ADO.NET conventions) in the connection string and pass this value to the SQL Server engine so it populates the program_name column in DMVs such as sys.dm_exec_sessions and sys.dm_exec_requests.
If the keyword app is reserved internally by the driver to identify itself, please consider exposing an alternative keyword (e.g., Application Name or App Name) or allowing the user to append to the existing driver-controlled string.
Justification & Impact
- DBA Visibility: Without this, all connections from this driver look identical on the server side, making it impossible to distinguish between different Python microservices, background jobs, or user scripts.
- Microsoft Ecosystem Parity: Setting the application name is a long-standing standard across Microsoft data access technologies:
- .NET (SqlClient):
Application Name - ODBC:
APP - JDBC:
applicationName - Go (
mssql):app name - OLE DB:
Application Name
- .NET (SqlClient):
- Migration: Python developers migrating from
pyodbcorpymssqlrely on this feature for logging and telemetry. Its absence creates a regression for enterprise applications migrating to the new native driver.
Environment details
- OS: Windows / Linux / macOS
- Python version: 3.11+
- Driver version:
mssql-pythonv1.3.0