We recently upgraded our SQL Server from 2008 to 2016. After the upgrade, most of the batch jobs that rely on SQL server went thru fine except one major failure. We have a daily extract job that extracts the data from SQL server in the form of XML and this job is failing with the below error message.
Foreach Loop Container,,,7/3/2019 6:17:00 AM,7/3/2019 6:17:00 AM,-1,0x,System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.Throw(String res, String arg) at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.LoadXml(String xml) at ST_c5c91743715e4a8fb7ffc01b09f1b1f8.vbproj.ScriptMain.CreateXMLOutputExtract(DataSet dsExtract, String strExtractFilePath, String strArchiveFilePath, String strFileName) at ST_c5c91743715e4a8fb7ffc01b09f1b1f8.vbproj.ScriptMain.Main()
The method that generates the XML output extract file is below.
Private Sub CreateXMLOutputExtract(ByVal dsExtract As DataSet, _ ByVal strExtractFilePath As String, _ ByVal strArchiveFilePath As String, _ ByVal strFileName As String) Dim strRootName = Dts.Variables.Item("strXMLRootElementNm").Value().ToString() Dim strXMLFileName = strFileName & "_" & strRootName Dim strXMLFile As String = strExtractFilePath & strXMLFileName & ".XML" Dim xmlDoc As New XmlDocument Dim strVar As String = "" Dim dt As DataTable = dsExtract.Tables(0) Dim iColCount As Integer = dt.Columns.Count For Each dr As DataRow In dt.Rows For i = 0 To iColCount - 1 If Not Convert.IsDBNull(dr(i)) Then strVar = strVar & dr(i).ToString End If Next Next 'If no results are returned the Root Name from the xMLRoot column in Subscription 'will be used as the tags. This change was made to meet a SAM business need. If strVar = "" Then strVar = "<" & strRootName & "></" & strRootName & ">" End If xmlDoc.LoadXml(strVar) ' Solves problem of empty nodes having CR/LF between start and end tags Dim Settings As New XmlWriterSettings() Settings.Indent = True Settings.OmitXmlDeclaration = True ' Suppress the xml header <?xml version="1.0" encoding="utf-8"?> Settings.Encoding = New System.Text.UTF8Encoding(False) ' Suppress hidden identifier Dim Writer As XmlWriter = XmlWriter.Create(strXMLFile, Settings) xmlDoc.Save(Writer) 'Create ArchiveFile if not blank If strArchiveFilePath <> "" Then CreateArchiveFile(strXMLFile, strArchiveFilePath, strXMLFileName, "XML") End If End SubCan someone help? FYI, the above method is used in a script task from a SSIS package.
I am a Salesforce developer and not a SQL/SSIS developer which makes me hard to troubleshoot.