Trying to Write Python Code from Connected Database

SWiL 20 Reputation points
2024-08-13T17:21:53.39+00:00

I have connected a data warehouse in VS Code via the MSSQL extension. It has successfully connected and I can query it directly. I now want to leverage SQL and Python within a singular notebook. All of the ways I have seen to do this require me to open a Jupyter Notebook and create a connection to a database. Since, I already have an existing connection via the extension, is there another way to do this?

I'd like to write a SQL query, generate a dataset, and then perform some analysis with Python on this. In one notebook, if possible. Is there a way to do this that doesn't require creating a new connection to the database? If not, it seems like connecting via the MSSQL extension wasn't very useful.

Azure SQL Database
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,760 questions
Visual Studio Setup
Visual Studio Setup
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Setup: The procedures involved in preparing a software program or application to operate within a computer or mobile device.
1,039 questions
0 comments No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 110.8K Reputation points MVP
    2024-08-13T21:28:05.2633333+00:00

    I would say that the answer is no. I have not worked with VS Code, but I guess that you get one connection per window. And these connections could be to different SQL Server instances or databases. So it would be a limiting if a notebook had to piggyback on an existing connection. Also, you want the Jupyter notebook to be standing on its own. The next person who runs it may not have your connections.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.