Currently, our .NET application creates XML data in memory that we store in a SQL Server database. The XElement object is converted to a string using ToString (), and then stored in the varchar (MAX) column in the database. We do not want to use the SQL XML data type, since we do not need any validation, and SQL does not need to query XML at any stage.
Although this implementation works fine, we want to reduce the size of the database by compiling the XML before saving it and unpacking it after retrieving it. Does anyone have some sample code for compressing an XElement object (and unpacking would be fine too)? Also, what changes do I need to make to the data type of the database column so that we can take full advantage of this compression?
I again examined the SQL Server 2005 XML data type, and the overhead of validation that it offers is too high for us to use. Also, although it compresses XML a bit, it is not so much compressed as the .NET DeflateStream class.
I tested the DeflateStream class by writing the XML that we use to disk and then save the comrpessed version as a new file. The results are great: a file with a size of 16 KB goes into a 3kb file, so it allows you to get this to work in memory and save the data in the database. Does anyone have sample code for compression, and do I need to change varcahr (MAX) colum to type, possibly to varbinary?
Thank you in advance
source share