我在批量插入时遇到了一个疯狂的问题。我正在使用PHP脚本创建数百个小的制表符分隔文件,然后将其批量插入SQL Server。每个文件的创建方式完全相同,并覆盖文件tmp.txt,然后将其批量插入到正确的表中。 tmp.txt是制表符分隔的,有换行符,没有回车符。我的批量插入语法说:
bulk insert RCB from
'E:\tmp\tmp.txt'
with(rowterminator = '0x0a', fieldterminator = '\t')
批量插入在某些文件上失败,无论是通过我的脚本运行还是直接在SSMS中运行,都会返回以下错误消息:
Msg 7399, Level 16, State 1, Line 3
The OLE DB provider "BULK" for linked server "(null)" reported an error. The
provider did not give any information about the error.
Msg 7330, Level 16, State 2, Line 3
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
我检查过几个失败的文件,看起来都很正确。使用其中一个文件,我尝试从文本文件中删除行并再次运行批量插入语句。我最终发现如果我只保留1到694行,那么批量插入就可以了。然后我想出了第695行中每个字符的ASCII码,没有奇怪的代码!只有标签和数字0-9。这显示了行693到697的每个ASCII字符代码的计数。(代码9是一个选项卡; 48-57是数字0-9)。
Array
(
[693] => Array
(
[57] => 6
[52] => 19
[54] => 19
[49] => 17
[9] => 379
[48] => 80
[50] => 15
[56] => 10
[53] => 13
[55] => 9
[51] => 13
)
[694] => Array
(
[57] => 13
[52] => 12
[55] => 9
[53] => 15
[9] => 379
[48] => 84
[49] => 12
[51] => 25
[54] => 5
[50] => 16
[56] => 3
)
[695] => Array
(
[57] => 11
[52] => 3
[56] => 7
[53] => 4
[9] => 379
[48] => 92
[51] => 11
[54] => 6
[50] => 10
[49] => 5
[55] => 2
)
[696] => Array
(
[57] => 5
[53] => 10
[48] => 86
[49] => 14
[9] => 379
[51] => 15
[56] => 6
[54] => 4
[52] => 11
[55] => 7
[50] => 9
)
[697] => Array
(
[57] => 7
[53] => 8
[54] => 10
[9] => 379
[48] => 92
[50] => 8
[51] => 4
[49] => 13
[52] => 5
[56] => 2
)
我完全不知道是什么打破了这个批量插入。有什么想法吗?