2011-12-01 122 views
0

错误列表SQL Server 2005的批量插入

Msg 4866, Level 16, State 7, Line 2
The bulk load failed. The column is too long in the data file for row 1, column 1. Verify that the field terminator and row terminator are specified correctly.

Msg 7399, Level 16, State 1, Line 2
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 2
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".

FMT文件

9.0 
10 
1  SQLCHAR  2  50  "," 2  EmployeeSSN  SQL_Latin1_General_CP1_CI_AS      
2  SQLCHAR  2  50  "," 3  DOB    SQL_Latin1_General_CP1_CI_AS      
3  SQLCHAR  2  50  "," 4  Gender   SQL_Latin1_General_CP1_CI_AS      
4  SQLCHAR  2  50  "," 5  Relcode   SQL_Latin1_General_CP1_CI_AS       
5  SQLCHAR  2  50  "," 6  EmployeeID   SQL_Latin1_General_CP1_CI_AS      
6  SQLCHAR  2  50  "," 7  AssessmentType  SQL_Latin1_General_CP1_CI_AS      
7  SQLCHAR  2  50  "," 8  MeasurementDate  SQL_Latin1_General_CP1_CI_AS      
8  SQLCHAR  2  50  "," 9  RecordCreationDate SQL_Latin1_General_CP1_CI_AS      
9  SQLCHAR  2  50  "," 10 AttributeID  SQL_Latin1_General_CP1_CI_AS        
10  SQLCHAR  2  50  "/r/n" 11 AttributeValue SQL_Latin1_General_CP1_CI_AS 

批量插入代码

BULK insert *******_raw_data 
from 'E:\*****_csv\BWC_To_*****_2.csv' 
with (formatfile = 'c:\*******_raw_data-n.fmt'); 

从CSV第一线

NULL,07/14/1983,F,S,105***,HRA,09/28/2011,09/28/2011,19,1 

我想弄清楚我在哪里错了....我已经得到了其他文件的工作,但一直没有成功。该文件的名称是在我的代码正确的他们出演,因为他们是公司名称

回答

1

第一个错误: 消息4866,级别16,状态7,2号线 大容量加载失败。数据文件中第1行第1列的列太长。验证字段终止符和行终止符是否正确指定。

这是NULL或行终止符的问题。 该行的最后一个终结符可能不是“/ r/n”,它可能是“/ n”。最好用十六进制编辑器来确认。

第二次和第三次错误: 这些都看起来像一个NULL问题。

处理BULK INSERT中的空值的正确方法是指定KEEPNULLS选项。

with (formatfile = 'c:\*******_raw_data-n.fmt',KEEPNULLS); 

为空值创建空白字段的CSV文件。

,07/14/1983,F,S,105***,HRA,09/28/2011,09/28/2011,19,1