问题描述
我尝试将文件从大容量复制到sqlserver 2008中的表中.它只是我要复制的文件的一部分(在下面的BCP命令示例中,我只会复制第3行).
I try to do a bulk copy from a file into a table in sqlserver 2008. Its only a part of the file that I want to copy (in the BCP command example bellow it is only line number 3 I will copy).
有时我会收到遇到意外的EOF"错误消息.
Sometimes I receive the "Unexpected EOF encountered" error message.
命令是:d:\ bc_file.txt中的BCP tblBulkCopyTest -F3 -L3 -c -t,-S(local)-Utest -Ptest
The command is:BCP tblBulkCopyTest in d:\bc_file.txt -F3 -L3 -c -t, -S(local) -Utest -Ptest
当文件如下所示时,该副本可以正常工作(第3行插入到我的表中):
When the file looks like the following, the copy works fine (the line number 3 is inserted into my table):
44261233,207,0,0,2168
44261234,207,0,0,2570
44261235,207,0,0,2572
当文件如下所示时,我收到遇到意外的EOF"错误消息:
测试
44261233,207,0,0,2168
44261234,207,0,0,2570
44261235,207,0,0,2572
When the file looks like the following, I receive "Unexpected EOF encountered" error message:
Test
44261233,207,0,0,2168
44261234,207,0,0,2570
44261235,207,0,0,2572
似乎文件开始时格式不正确,即使不是我要复制的行(在bcp命令中,我指定的行号为3),BCP命令也会失败.
It seems like when the file starts with something not in the correct format, the BCP command fails, even though it is not the line I want to copy (in the bcp command I have specified line number 3).
当文件如下所示时,副本可以正常工作:
When the file looks like the following, the copy works fine:
44261233,207,0,0,2168
44261234,207,0,0,2570
44261235,207,0,0,2572
Test
所以只有当文件中要复制的行之前"有一些不正确的数据时,我才会收到错误.
So it is only when the file has some incorrect data "before" the lines I want to copy, that I receive the error.
有人建议BCP命令如何忽略行,而不是问题?
Any suggestions how the BCP command will ignore the lines, not in question?
推荐答案
我每天解决此类错误的方式:
The way I solve that kind of errors every day:
1)使用单列tblRawBulk(RawRow varchar(1000))创建一个表.
1) Create a table with single column tblRawBulk(RawRow varchar(1000)).
2)在其中插入所有行.
2) Insert all of the rows there.
3)使用WHERE参数删除不必要的未格式化行(例如,示例中的测试").甚至删除所有不必要的行(需要加载的行除外)以简化第5点.
3) Remove unnecessary unformatted rows (e.g. 'test' in your example) with WHERE-parameter. Or even remove all unnecessary rows (except of rows, that you need to load) to simplify point 5.
4)将带有BCP的表上传到某些工作文件夹.
4) Upload this table with BCP to some workfolder.
5)下载此新文件.
这不完全是您想要的,但是如果您编写相应的存储过程可以自动完成所有这些操作,则可能会有所帮助.
It's no exact what you want, but may help if you'll write corresponding stored procedure, that can automatically do all this things.
这篇关于BCP意外EOF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!