Convert raw byte[8192] of SQL Server XML datatype into a C# string?
-
I'm trying to get the project GitHub - improvedk/OrcaMDF: A C# parser for MDF files. Allows you to read tables, metadata and indexes from MDF files without it being attached to a running SQL Server instance.[^] to work with the XML SQL Server data type. When I step in the debugger, I can see that I receive an array byte[8192] with XML-data (each ASCII character seems to occupy 2 bytes) in the file \OrcaMDF\src\OrcaMDF.Core\Engine\Records\TextRecord.cs:line 35. Does anybody know how I can retrieve the proper XML-string? I guess the start index and length of the string must be baked into the array somehow.
-
I'm trying to get the project GitHub - improvedk/OrcaMDF: A C# parser for MDF files. Allows you to read tables, metadata and indexes from MDF files without it being attached to a running SQL Server instance.[^] to work with the XML SQL Server data type. When I step in the debugger, I can see that I receive an array byte[8192] with XML-data (each ASCII character seems to occupy 2 bytes) in the file \OrcaMDF\src\OrcaMDF.Core\Engine\Records\TextRecord.cs:line 35. Does anybody know how I can retrieve the proper XML-string? I guess the start index and length of the string must be baked into the array somehow.
You could try
string xml = System.Text.UnicodeEncoding.GetString(theByteArray);
If this does not produce proper result, you could also try one of other encodings provided by the framework: Encoding Class (System.Text) | Microsoft Docs[^].
"Five fruits and vegetables a day? What a joke! Personally, after the third watermelon, I'm full."