title: Why does Format File cause error during SQL Server Bulk Insert?
body: <p>I am trying to bulk insert a CSV file into SQL Server 2017 using an XML Format File: </p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;BCPFORMAT xmlns="https://schemas.microsoft.com/sqlserver/2004/bulkload/format" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;RECORD&gt;
          &lt;FIELD ID="Col_0" xsi:type="CharTerm" MAX_LENGTH="100" TERMINATOR=","/&gt;
          &lt;FIELD ID="Col_1" xsi:type="CharTerm" MAX_LENGTH="100" TERMINATOR=","/&gt;
          &lt;FIELD ID="Col_2" xsi:type="CharTerm" MAX_LENGTH="3" TERMINATOR=","/&gt;
          &lt;FIELD ID="Col_3" xsi:type="CharFixed" Length="19" TERMINATOR=","/&gt;
          &lt;FIELD ID="Col_4" xsi:type="CharFixed" Length="19" TERMINATOR=","/&gt;
          &lt;FIELD ID="Col_5" xsi:type="CharFixed" Length="53" TERMINATOR=","/&gt;
          &lt;FIELD ID="Col_6" xsi:type="CharFixed" Length="10" TERMINATOR=","/&gt;
      &lt;/RECORD&gt;
      &lt;ROW&gt;
          &lt;COLUMN SOURCE="Col_0" NAME="NAME" xsi:type="SQLVARCHAR"/&gt;
          &lt;COLUMN SOURCE="Col_1" NAME="MATCHNAME" xsi:type="SQLVARCHAR"/&gt;
          &lt;COLUMN SOURCE="Col_2" NAME="CHROMOSOME" xsi:type="SQLVARCHAR"/&gt;
          &lt;COLUMN SOURCE="Col_3" NAME="START_LOCATION" xsi:type="SQLBIGINT"/&gt;
          &lt;COLUMN SOURCE="Col_4" NAME="END_LOCATION" xsi:type="SQLBIGINT"/&gt;
          &lt;COLUMN SOURCE="Col_5" NAME="CENTIMORGANS" xsi:type="SQLFLT4"/&gt;
          &lt;COLUMN SOURCE="Col_6" NAME="MATCHING_SNPS" xsi:type="SQLSMALLINT"/&gt;
      &lt;/ROW&gt;
  &lt;/BCPFORMAT&gt;
  </code></pre>
  
  <p>When I execute this, I get this error message:</p>
  
  <blockquote>
    <p>Error during Execute
     37000(4855)[Microsoft][ODBC SQL Server Driver][SQL Server]Line 2 in format file "c:\temp\FormatFile.xml": unexpected element "BCPFORMAT".</p>
  </blockquote>
  
  <p>I'm at a loss to understand why the BCPFORMAT element is not recognized. The XML is properly formatted according to Altova XMYSpy. </p>
  
  <p>The code to perform the upload is:</p>
  
  <pre><code>bulk insert FF_ChromBrwResults_20190124 from 'c:\temp\temp.csv'
   with (FIELDTERMINATOR = ',',FIRSTROW =1,ROWTERMINATOR = '\n'
  ,KEEPIDENTITY,CODEPAGE ='OEM',KEEPNULLS, FORMATFILE = 'c:\temp\FormatFile.xml' ) 
  </code></pre>
  
  <p>The CSV has many rows in this format, ending with a linefeed:</p>
  
  <blockquote>
    <p>Name1,Name2, 1,48745397,54260005,2.84,1000</p>
  </blockquote>
  
  <p>I've tried executing this from .NET code and in AQT where the ODBC connection is working; both methods produced the same error.  </p>