Jupyter notebooks for C#/SQL

by on under programming
6 minute read

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.

azure-data-studio-python

VS Code Python

Behaves as expected.

vs-code-python

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-ipython-classic

Binder new JupyterLab Python 3

Behaves as expected.

binder-python3-new

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

azure-data-studio-csharp

Articles

Also see

Videos

Other tools

comments powered by Disqus