Search code examples
biztalkbiztalk-2016

BizTalk CSV with headers and no data rows gives error: Unexpected end of stream while looking for: ','


My BizTalk CSV schema works fine when there is one or more rows of data in the CSV file. It's a fairly normal CSV with commas as the delimiter on each row. My receive pipeline points to the document schema only.

But if the CSV file has headers only, I get the error:

There was a failure executing the receive pipeline: Source: "Flat file disassembler" Reason: Unexpected end of stream while looking for: ',' The stream offset where the error occured is 310. The line number where the error occured is 2. The column where the error occured is 0.

This is the file in NotePad++ with the special characters turned on. Line 1 ends with CRLF (CarriageReturn/LineFeed), and the CRLF are the last two characters in the file. enter image description here

Here's an image of the schema, which shows how I handled the headers. It's actually the first time I've done headers this way, and it was working great until I got the files with headers-only.

enter image description here

Below is my schema except I have only included two fields. I'm hoping it just a matter of tweaking one of the schema options. I switched allow-early-termination and suppress-empty-nodes to True, but that had no effect on the error.

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://ABC.Schemas.ScadaDisabledOPCAnalogs" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://ABC.Schemas.ScadaDisabledOPCAnalogs" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:annotation>
    <xs:appinfo>
      <schemaEditorExtension:schemaInfo namespaceAlias="b" extensionClass="Microsoft.BizTalk.FlatFileExtension.FlatFileExtension" standardName="Flat File" xmlns:schemaEditorExtension="http://schemas.microsoft.com/BizTalk/2003/SchemaEditorExtensions" />
      <b:schemaInfo standard="Flat File" codepage="1200" default_pad_char=" " pad_char_type="char" count_positions_by_byte="false" parser_optimization="speed" lookahead_depth="3" suppress_empty_nodes="true" generate_empty_nodes="false" allow_early_termination="true" early_terminate_optional_fields="false" allow_message_breakup_of_infix_root="false" compile_parse_tables="false" root_reference="ScadaDisabledOPCAnalogs" />
    </xs:appinfo>
  </xs:annotation>
  <xs:element name="ScadaDisabledOPCAnalogs">
    <xs:annotation>
      <xs:appinfo>
        <b:recordInfo structure="delimited" child_delimiter_type="hex" child_delimiter="0xD 0xA" child_order="postfix" sequence_number="1" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
      </xs:appinfo>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:annotation>
          <xs:appinfo>
            <groupInfo sequence_number="0" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
          </xs:appinfo>
        </xs:annotation>
        <xs:element maxOccurs="1" name="Header">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter="," child_order="infix" sequence_number="1" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:annotation>
                <xs:appinfo>
                  <b:groupInfo sequence_number="0" />
                </xs:appinfo>
              </xs:annotation>
              <xs:element name="Header01" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo sequence_number="1" justification="left" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="Header02" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo sequence_number="2" justification="left" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element maxOccurs="unbounded" name="Row">
          <xs:annotation>
            <xs:appinfo>
              <b:recordInfo structure="delimited" child_delimiter_type="char" child_delimiter="," child_order="infix" sequence_number="2" preserve_delimiter_for_empty_data="true" suppress_trailing_delimiters="false" />
            </xs:appinfo>
          </xs:annotation>
          <xs:complexType>
            <xs:sequence>
              <xs:annotation>
                <xs:appinfo>
                  <groupInfo sequence_number="0" xmlns="http://schemas.microsoft.com/BizTalk/2003" />
                </xs:appinfo>
              </xs:annotation>
              <xs:element name="Id" type="xs:int">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo sequence_number="1" justification="left" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
              <xs:element name="ParentGroupName" type="xs:string">
                <xs:annotation>
                  <xs:appinfo>
                    <b:fieldInfo sequence_number="2" justification="left" />
                  </xs:appinfo>
                </xs:annotation>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Related question that didn't really have an answer: BizTalk Flat file parsing Unexpected end of stream while looking for:','


Solution

  • You need to set the Min Occurs on the Row Record to 0, then it validates if you only have a header row.

    Schema properties

    Payload