1
votes

I want to pass some zipped XML files into SQL Server 2008 which is compatible with .NET 2.0. (implementing c# to be imported as CLR).

I downloaded a .zip file from an API and this .zip file contains several XML files. Is there any way to decompress the get the XML's using .NET 2.0? The use of external libraries is not possible.

The export of the file is done by this code:

byte[] varbinary = GetStreamFileResult(..);
string tempPath = Path.GetTempPath()+ "temp.zip";
File.WriteAllBytes(tempPath, varbinary); // Requires System.IO

In my research I found solution like this but they are not applicable to my case.

2
Is no external software allowed? 7-zip, for example, is free and has a good command line interface - HoneyBadger
Frankly, I think you've misunderstood the intended use-case of .NET inside SQL Server; performing http queries and creating zip files seems very far outside what you should be doing - it is actually quite horrifying as an observer. You should be doing these things on an application server - not in the RDBMS. - Marc Gravell
@MarcGravell I understand that CLR are bad practice but the whole system is using SQL-Delphi(don't ask..). This task needs to be scheduled every day and we have big problem with Microsoft Agent. On the other hand the SQL job Agent is very reliable. - Manos
@HoneyBadger The problem is that I cannot guarantee that the system will have 7-zip (or any related) installed. - Manos

2 Answers

6
votes

In later versions of the framework: this is readily available.

In 2.0: there are external libraries that expose this, but you say that isn't allowed.

So: if it isn't in the 2.0 framework and you can't use external libraries, you'd have to code a zip decoder from scratch. This is a significant amount of work and is almost certainly not a good idea. It would be a better move to challenge either of the two imposed limitations. Or: stop trying to run application code inside the database (that isn't what it is intended for).

0
votes

If upgrading to a higher version of .NET Framework isn't possible and neither is referencing a 3rd party library, your next best option would be to find an open source compression library project with a permissive license and then copy and paste the bits from it that are required to decompress your zip file.