Jupyter notebooks for C#/SQL
Jupyter notebooks for C#/SQL
This article is mostly based around ADS (Azure Data Studio) version: 1.25.3
Technologies involved
- Jupyter notebooks
- .NET Interactive
- SSMS
- Azure Data Studio
- .NET 5
- VS Code
- SQL
Some usage notes
- You will still need a local or remote SQL server to run the SQL kernel.
- Memory seems more than SSMS, 369 MB Azure Data Studio vs 150 MB SSMS 2017.
- 416 MB Visual Studio 2017 vs VS Code 361 MB.
- Use Azure Data Studio for SQL.
- Use VS Code for .NET.
- Azure Data Studio uses
sql-data-tools
like the mssql VS Code extension. - Azure Data Studio allows for notebooks and graphing? etc unlike mssql extension for VS Code.
- Much like VS Code the project management is done by opening folders primarily. This is useful to have in Azure Data Studio because I can have a window open with all my notebooks (querying ad-hoc or investigatory response) and a window open with all my
.sql
scripts (report or DBA tasks). - Could do with an option for markdown as the default for new text cells.
- ADS
ctrl + r
don’t work but F5 does, tab key moves across column but right arrow doesn’t. - Doesn’t allow for multiple SQL server connections per a notebook yet.
- Cant call a
.sql
script from inside the code cell yet. See: azuredatastudio/issues/8467 - ADS cant select columns/rows via shift key but can individually via
ctrl
or totally via top left corner. See: azuredatastudio/issues/2727- Can however drag to highlight results.
- ADS Scrolling can be a bit confusing.
- It’s simply because the mouse falls inside a code block which steals the scroll wheel.
- Try position pointer to the far left or right hand side to avoid that happening.
- SSMS 2018 installs a copy of Azure Data Studio (system) by default
- SSMS 2018 still doesn’t have a dark theme option in settings without modifying a reg key.
- VS Code seemed to try opening the notebook using a different kernel e.g. Pyspark instead of Python 3.
- This is a notebook created/saved in ADS and opened in VS Code.
Questions I had
.ipynb
extension vs “.NET Interactive” notebooks.dib
extension?- Looks like they favour the prior currently.
- Exporting to PDF?
- APIs? Use JavaScript, C# or Python as a client.
- bc support? (basic calculator) or as I call it (best calculator).
- Bash scripts?
- Why UI isn’t the same as VS Code notebooks? Shared UI lib and/or better end user continuity.
Python oddities between VS Code and ADS
I was doing some testing of Python vs C# regarding the ability to comment out indented code blocks quickly. Specifically without having to shift indentation around.
During my testing I noticed some disparities between ADS and VS Code Python kernel.
- Why Python behaves differently?
- Perhaps ADS has some different flags enabled on the Python interpreter?
- Perhaps ADS uses IPython and VS Code uses regular Python? The prior maybe less strict with indentation?
- Perhaps Python version differences?
- VS Code seems to use system installs whereas Azure Data Studio has a pre-bundled Python?
- I tried creating fresh notebooks in each instead of creating in one and opening in other. The same behaviour was observed.
Invoking the ADS bundled Python manually
Behaves as expected. Python forcing us to indent properly for readability and in some cases functionality due to lack of braces in the language.
C:\Users\peter\azuredatastudio-python\0.0.1\python.exe Desktop\test.py
File "Desktop\test.py", line 2
print("test")
^
IndentationError: unexpected indent
Invoking the system installation of Python manually.
Behaves as expected.
C:\Windows\py.exe Desktop\test.py
File "C:\Users\peter\Desktop\test.py", line 2
print("test")
IndentationError: unexpected indent
ADS Python
Surprised it didn’t moan at me.
VS Code Python
Behaves as expected.
Digging a bit further I tried this in binder and noticed something similar.
Binder classic notebook IPython
Surprised it didn’t moan at me.
Binder new JupyterLab Python 3
Behaves as expected.
ADS .NET 5 C#
Behaves as expected. We use braces for scope therefore it’s never forcing us to whitespace indent properly which is useful for quickly commenting out a few blocks of surrounding code for debugging purposes. See: C# if-else statement: Curly braces or not? An in-depth analysis
Articles
- How to Use .NET Interactive Jupyter Notebooks in Daily Work-Life | Data Exposed: MVP Edition
- Show preview kernels for current notebook provider.
- .NET Interactive is here! | .NET Notebooks Preview 2
- Jupyter kernels - List of available kernels
- Jupyter notebook with multiple languages
- The November 2019 release of Azure Data Studio is now available
- Not entirely sure why I included this link in my draft. Perhaps it was referral from another doc judging the ref id.
- Azure Data Studio FAQ
- Specifically the following FAQ questions are interesting:
- “Now that there’s Azure Data Studio, does Microsoft plan to deprecate SSMS and SSDT?”
- “When Should I Use Azure Data Studio or SQL Server Management Studio?”
- Specifically the following FAQ questions are interesting:
- What is Azure Data Studio?
Also see
- 2E0PGS blog - A state of .NET in late 2020
- I touch on .NET Interactive Notebooks and include a link to Philip Carter’s presentation with F# notebooks.
- 2E0PGS blog - REPL maths and notation
- Some Jupyter kernels are built on top of REPLs.
Videos
- Bringing .NET Interactive to Azure Data Studio Notebooks
- Jupyter Notebooks in Azure Data studio | Azure Data Studio Tutorial
- Introduction to Azure Data Studio Notebooks | Data Exposed
- How to use Jupyter Notebooks in Azure Data Studio | Azure Friday
- Plotting Graphs in C# with XPlot and Jupyter
- VSCode’s Python Interactive mode is AMAZING!
Other tools
- nteract.io
- Interactive apps using notebooks and REPLs.
- XPlot F# graphing lib.
- Use Jupyter with .NET Interactive on Binder
- mybinder.org/v2/gh/dotnet/interactive
- No syntax highlighting on the mybinder currently.
- mybinder.org/v2/gh/dotnet/interactive
- binder “Turn a Git repo into a collection of interactive notebooks”
- Azure Notebooks
- IPython Interactive Python
- Jupyter - Try Jupyter
Let me know what you think of this article on twitter @M3PGS or leave a comment below!