As @Likhan is mentioning in his answer, it seems that the information is saved in Unicode/UTF16
so it needs to be decoded using other Encoding
like iso-8859-1.
I developed a workaround for it developing a SQL CLR Stored Procedure
SQL CLR STORED PROCEDURE
public partial class StoredProcedures {
[SqlProcedure]
public static void GetComponentPresentationContent(SqlInt32 publicationId, SqlInt32 componentId, SqlInt32 templateId) {
using (SqlConnection connection = new SqlConnection("context connection=true")) {
try {
connection.Open();
SqlCommand command = connection.CreateCommand();
command.CommandType = CommandType.Text;
command.CommandText =
string.Format("SELECT CONTENT FROM COMPONENT_PRESENTATIONS WHERE PUBLICATION_ID = {0} AND COMPONENT_ID = {1} AND TEMPLATE_ID = {2}",
publicationId, componentId, templateId);
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows) {
SqlDataRecord record = new SqlDataRecord(new SqlMetaData[] { new SqlMetaData("CONTENT", SqlDbType.VarChar, -1) });
SqlContext.Pipe.SendResultsStart(record);
while (reader.Read()) {
string content = reader.GetString(0);
using (MemoryStream ms = new MemoryStream()) {
byte[] encoded = Encoding.Unicode.GetBytes(content);
ms.Write(encoded, 0, encoded.Length);
ms.Seek(0, SeekOrigin.Begin);
StreamReader tr = new StreamReader(ms, true);
Encoding targetEncoding = Encoding.GetEncoding("iso-8859-1");
content = targetEncoding.GetString(ms.ToArray());
record.SetSqlString(0, content);
SqlContext.Pipe.SendResultsRow(record);
}
}
SqlContext.Pipe.SendResultsEnd();
}
}
catch (Exception ex) {
throw ex;
}
finally {
if (connection.State != ConnectionState.Closed) {
connection.Close();
}
}
}
}
}
SQL ASSEMBLY CREATION
CREATE ASSEMBLY [TridionBroker]
FROM '[YOUR ASSEMBLY PATH]'
SQL STORED PROCEDURE CREATION
CREATE PROCEDURE GetComponentPresentationContent
@PUBLICATIONID AS INT,
@COMPONENTID AS INT,
@TEMPLATEID AS INT
AS
EXTERNAL NAME [TridionBroker].StoredProcedures.GetComponentPresentationContent
TEST
EXEC GetComponentPresentationContent 11, 190, 200
It will return the component presentation in a readable format from your database. I hope this helps.