Why do I get "XML parsing: line 2, character 0, incorrect document syntax" when Bulk Inserting in MS SQL Server

Also another point just in case anyone else runs into this...

If you're sure the file is ANSI but still getting this error check the first line of the format file (the version number). The version number must match your SQL version number (or be an older version number).

MSDN reference:

The version of the bcp utility (Bcp.exe) used to read a format file must be the same as, or a later version than was used to create the format file. For example, SQL Server 2008 bcp can read a version 9.0 format file, which is generated by SQL Server 2005 bcp, but SQL Server 2005 bcp cannot read a version 10.0 format file, which is generated by SQL Server 2008 bcp.


A good way to ensure that the MS SQL server is not failing to read the version format, downgrade the version number in the .FMT file. Change V10.0 to 9.0 or lower. MS SQL 2008 can read a lower version but 2005 cannot read a higher version. So downgrading the version numer might help solve the problem.

Version number of the bcp utility:

 9.0 = SQL Server 2005 
10.0 = SQL Server 2008
11.0 = SQL Server 2012
12.0 = SQL Server 2014

For non XML format file you can refer to the Microsoft page: http://msdn.microsoft.com/en-us/library/ms191479.aspx.


If the format file is encoded as Unicode the bulk insert will automatically think it is an XML-file and treat it as such. Make sure the file is encoded as ANSI and you should be fine.