Search code examples
c#sql-serverclrsqlclr

Generate a XLS file using SQL CLR That does not have loads of incompatible Dependencies


I want to do something simple, Create a SQL CLR that converts data to XLS.

I've tried Using OpenXML, but it keeps installing windowbase as a dependency, which uses system.XAML, which SQL server (2019) refuses to install as it's not "tested" whatever that means.

ClosedXML has a similar issue, System.Drawing refuses to be referenced.

I tried writing raw xml to xls and The io.Compression dependency file won't work with SQL server either!

I'm out of ideas, All I really want is a version of openXML that isn't using WPF Nonsense like system.xaml, but I can't seem to get that to work.

Any help is appreciated.


Solution

  • Don't try do this in SQLCLR. Instead Build a .NET console application to do the work, and invoke it from an Agent job or even xp_cmdshell.

    In modern .NET you can even combine your app and all the dependencies into a single .exe as a Single-File Application.