Save Xml to database append (?) at beginning of the first line

Hi,

I have this code to save xml to database:
 Dim ms As New MemoryStream, m_Buffer() As Byte, m_XML As String = ""

        myDashboard.SaveToXml(ms)
        m_Buffer = ms.ToArray()
        ms.Flush()
        ms.Close()

        m_XML = System.Text.Encoding.UTF8.GetString(m_Buffer)
         
        '-----
        Dim SqlDoc As String = "UPDATE Dash Set DashStream = @DashStream where Idstamp = @Idstamp"
        Dim sqlconn As SqlConnection = New SqlConnection(CBD.ConnectionStringBD)
        sqlconn.Open()
        Dim Com As New SqlCommand(SqlDoc, sqlconn)
        Com.Parameters.Add("@IdstampDashBoard", SqlDbType.VarChar, 50).Value = mIdStampDashBoard
        Comm.Parameters.Add("@DashBoardStream", SqlDbType.VarChar, -1).Value = m_XML
        Dim x As Integer = CommandActualiza.ExecuteNonQuery()
        sqlconn.Close()

Open in new window

Works fine but appends a (?) at beginning of the first line like example:
?<?xml version="1.0" encoding="utf-8"?>

But only when saved in database, Analyzing with debug (m_XML) in this line (Comm.Parameters.Add("@DashBoardStream", SqlDbType.VarChar, -1).Value = m_XML) the string is correct whitout (?) character.

I tried to change encoding but it appends one or two characters in beginnig also.

Table field is Varchar(MAX).
best regards
rflorencioAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
When I need to guess: Problem with the encoding and the BOM.. hard to tell without the real data.
rflorencioAuthor Commented:
Hi,

This the file saved in database, but removed (?) from the beginning ?<?xml version="1.0" encoding="utf-8"?>

best regards
XmlExample.xml
Fernando SotoRetiredCommented:
Hi rflorencio;

Why have you set the size of the data to be -1 in the following statement?
Comm.Parameters.Add("@DashBoardStream", SqlDbType.VarChar, -1).Value = m_XML

Open in new window

Should it not be something like the following?
Comm.Parameters.Add("@DashBoardStream", SqlDbType.VarChar, m_XML.Length).Value = m_XML

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

rflorencioAuthor Commented:
Hi,

No, this is not the problem.

best regards
Fernando SotoRetiredCommented:
I guess I am asking why you have the data as having no size?
rflorencioAuthor Commented:
Hi,

I have always used this value for varchar max. But I also tried with your code and it gives the same.

best regards
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.