News

Microsoft Open Sources .NET 5 C# Language Extension for SQL Server

Microsoft has open sourced a .NET 5 C# Language Extension for SQL Server, allowing developers to work with relational data in the company's flagship programming language.

The new tool joins similar extensions the company has open sourced over the past year or so for other languages, all taking advantage of a new kind of Language Extensions architecture, a SQL Server feature used for executing external code. While such code execution is isolated from the core engine processes, it is fully integrated with SQL Server query execution.

Component Architecture
[Click on image for larger view.] Component Architecture (source: Microsoft).

Microsoft says Language Extensions provides advantages such as:

  • Data security. Bringing external language execution closer to the source of data avoids insecure data movement.
  • Speed. Databases are optimized for set-based operations.
  • Ease of deployment and integration. SQL Server is the central point of operations for many other data management tasks and applications. By using data in the database, you ensure that the data used by the language extension is consistent and up-to-date.

After previously open sourcing tools for Java and R/Python last year, the .NET Core CSharp Language Extension is now on GitHub.

In the SQL Server Language Extensions scheme, any supported external language can be run by calling a stored procedure, with the results being returned as tabular data directly to SQL Server so it can easily use the external language from any application that can send a SQL query and handle the results. In the new tool, that's done with a DataFrame, which stores data as a collection of columns.

"This extension is yet another example of using the developed programming language extensibility architecture which provides integration with a new type of language extension," said Nikita Takru, program manager, Azure Data Team, in a Sept. 8 blog post. "This latest architecture allows customers to have the freedom to use existing SQL Server tables which they can pass to a C# application as a DataFrame.

"Then, they can perform operations in C#, use the rich libraries, and obtain back a result set. One of the reasons to use C# is to reuse existing customer C# code, calculations, logic, or extensive libraries that provide functionality which you cannot get in T-SQL. We encourage developers to use the .NET 5 C# Language Extension and build on it."

Possible use case advantages include:

  • Data cleaning.
  • Fast data querying.
  • Any processing in C# can now occur through a DataFrame.
  • Customers are not limited to the T-SQL language surface area.
  • C# application development teams that leverage SQL Server as backend storage can now even embed C# code in stored procedures which enables pushing business logic down into the database for better performance.
  • Avoid unnecessary data movement and latency when data must be retrieved from SQL Server and moved into the app tier to do the business logic processing.

By studying the publicly documented Extensibility Framework API for SQL Server and the tool's source code on the above-linked GitHub repo, Takru said community developers can continue to develop and contribute additional programming language extensions.

Other resources to help learn about the new offering and such language extensions in general include a Regex Sample available on GitHub that shows how to create a .NET Core C# program that receives two columns (ID and text) from SQL Server and a regular expression as an input parameter. The class returns two columns back to SQL Server (ID and text).

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus

Featured

  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube