SQLServerCentral Article

Native C# in Stored Procedures

,

Language independence is one of the main selling points for using the .NET framework. Whether you are a VB, C#, COBOL, Python, or some other language expert, you can write using the .NET framework. You can even mix and match  languages for modules from different developers in the same application.

With the release of SQL Server 2014, we now have this capability inside SQL Server. This was one of the little known, and rarely talked about features, as it was on the bubble of being included, but we're letting you know today that it's available.

If you want to write native C# in a stored procedure, have it automatically compile and run inside SQL Server, you can now do that. You don't need to use the SQLCLR and create an assembly that you need to separately load. Now you can  write the C# in Management Studio, execute it on the server (which will call the C# compiler to produce the ILM code), and if the compile completes, you can immediately call the stored procedure or function from your application. This means you can now write

CREATE PROCEDURE MyAggregateProc
as

The big caveat here is that your code must compile cleanly. This means no errors, and no warnings from the compiler. If either of those occur, you will receive the warnings and errors back in your editor, and the new procedure or function will not be stored on the server. The other big caveat is that this is an April Fool's joke and not true at all.

Perhaps we'll get native compilation in other languages at some point, and we certainly get some better performing natively compiled code with the Hekaton enhancements in SQL Server 2014, but for now we can't write VB.NET, C#, Python, or any other .NET language natively inside SQL Server.

Rate

4.22 (27)

You rated this post out of 5. Change rating

Share

Share

Rate

4.22 (27)

You rated this post out of 5. Change rating