microsoft / microsoft/vscode-mssql
[Feature Request]: Allow Python cells in SQL Notebooks to reuse the SQL kernel's active connection
- Dominant language
- TypeScript
- Stars
- 1.9k
- Forks
- 610
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 97
Description
### Feature Description
**Context of the feature: **
Currently, SQL Notebooks in the MSSQL extension support mixing SQL cells (via the built-in SQL kernel) and Python cells (via the Jupyter extension) in the same .ipynb file. However, the Python kernel has no access to the connection already established by the SQL kernel — a Python cell that needs to query the database has to open its own separate connection (e.g., via pyodbc) using the same server/credentials again.
This creates duplicate connection setup within a single notebook, even though the notebook is already connected to a SQL Server instance through the MSSQL extension's connection dialog.
**Requested capability: **
Expose the notebook's active SQL connection (server, database, auth context) to Python cells in some way — for example, a helper variable or function (e.g., mssql.get_connection()) that Python cells can call to get a ready-to-use connection object, instead of hardcoding a new pyodbc.connect(...) call with duplicated connection details.
At minimum, expose the current connection profile's parameters (server, database, auth type) as an accessible notebook variable so Python cells can build a connection without the user having to re-type/re-store connection strings.
**Why it matters: **
Avoids duplicating credentials/connection strings inside notebook Python cells (better for security and maintainability — one connection profile to manage, not two).
Matches the workflow SQL Notebooks are meant to enable: mixing T-SQL queries and Python analysis in one seamless notebook, without the user having to leave the "already connected" context just because a cell's language changed.
Related prior discussion: #19753 raised similar friction around per-cell/connection overhead in SQL Notebooks.
### Problem and Motivation
Running a T-SQL query for row-count/table validation via a SQL cell, then wanting a Python cell in the same notebook to post-process and export those results (e.g., to a formatted Excel file or HTML report) without re-establishing a redundant connection to the same server.
### Related Area
- [x] Connection dialog (SQL Server | Azure browse/Fabric browse)
- [ ] Query editor
- [ ] Query results panel
- [ ] Object Explorer
- [ ] GitHub Copilot integration
- [ ] Preview/Edit data
- [ ] Table Designer
- [ ] Schema Designer
- [ ] Schema Compare
- [ ] Local SQL Server Container provisioning
- [ ] SQL database in Fabric provisioning
- [ ] DACPAC/BACPAC export/import
- [ ] SQL Database projects
- [ ] Query Plan Visualizer
- [ ] Other (please describe below)
### If you selected "Other", please describe the area
_No response_
### Confirmation
- [x] I have searched existing feature requests and couldn't find a match
- [x] I want to help implement this feature
Contributor guide
No contributing guide indexed for this repository
Research direction
No files or tests are identified. Start by locating the SQL Notebook connection-dialog handling and its Jupyter integration, then determine how the active connection profile could be exposed safely to Python cells. Done means Python cells can reuse the notebook's active SQL connection or profile without duplicating credentials, with coverage for the supported connection and authentication contexts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter, python, sql, typescript
- Domain
- databases, developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100