为什么我会收到“XML 解析:第 2 行,字符 0,文档语法不正确”在 MS SQL Server 中批量插入时
我正在使用 FMT 格式文件对表进行批量插入,但出现以下错误:
XML parsing: line 2, character 0, incorrect document syntax
这是我的代码
BULK INSERT [DM_Flux].[dbo].[Stage] FROM 'C:\temp\data.dat'
WITH (FORMATFILE = 'C:\temp\FormatBcp.fmt')
这是格式文件(标准格式文件,而不是 XML):
10.0
5
1 SQLCHAR 0 2 "" 1 Id ""
2 SQLCHAR 0 40 "" 2 Name ""
3 SQLCHAR 0 50 "" 3 Street ""
4 SQLCHAR 0 8 "" 4 StreetNo ""
5 SQLCHAR 0 300 "\r\n" 7 BulkData ""
为什么我会收到 XML 错误?
I'm doing a BULK INSERT into a table using a FMT format file, but I get the following error:
XML parsing: line 2, character 0, incorrect document syntax
Here is my code
BULK INSERT [DM_Flux].[dbo].[Stage] FROM 'C:\temp\data.dat'
WITH (FORMATFILE = 'C:\temp\FormatBcp.fmt')
Here is the formatfile (standard format file, not XML):
10.0
5
1 SQLCHAR 0 2 "" 1 Id ""
2 SQLCHAR 0 40 "" 2 Name ""
3 SQLCHAR 0 50 "" 3 Street ""
4 SQLCHAR 0 8 "" 4 StreetNo ""
5 SQLCHAR 0 300 "\r\n" 7 BulkData ""
Why do I get an XML error with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
还有一点,以防万一其他人遇到这个问题...
如果您确定该文件是 ANSI 但仍然收到此错误,请检查格式文件的第一行(版本号)。版本号必须与您的 SQL 版本号匹配(或者是旧版本号)。
MSDN 参考:
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:
确保 MS SQL Server 不会无法读取版本格式的一个好方法是降级 .FMT 文件中的版本号。将 V10.0 更改为 9.0 或更低版本。 MS SQL 2008可以读取较低版本,但2005无法读取较高版本。因此,降级版本号可能有助于解决问题。
bcp 实用程序的版本号:
对于非 XML 格式文件,您可以参考 Microsoft 页面: http://msdn.microsoft.com/en-us/library/ms191479.aspx。
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:
For non XML format file you can refer to the Microsoft page: http://msdn.microsoft.com/en-us/library/ms191479.aspx.
如果格式文件被编码为 Unicode,批量插入将自动认为它是 XML 文件并按此处理。确保文件编码为 ANSI 就可以了。
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.