1

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.

17
  • Retrieve the rows in a c# client, in a datagrid for example, and convert the datagrid ? I am sure there are lots of libraries that can help with that Commented Dec 17, 2024 at 14:21
  • Getting the data isn't the part that is stopping me, but the actual conversion to an XLS. OpenXML and CLosedXML are recommended but both have severe incompatibablities with SQL server assemblies Commented Dec 17, 2024 at 14:22
  • You can use SQL Server Integration Services (SSIS). It has Excel Destination Adapter. Commented Dec 17, 2024 at 14:23
  • 1
    Why, out of interest, do you want an XLS, rather than an XLSX file? The former are for much older Excel files. Commented Dec 17, 2024 at 14:26
  • 1
    Well a CSV in Powershell would be trivial. Just use DbaTools's Export-DbaDbTableData function. Commented Dec 17, 2024 at 14:40

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

The idea was to circumvent xp cmdshell due to security concerns. But I'm now starting to think that this entire process simply isn't fit for a sql clr and am going to look for alternatives like you suggested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.