lunes, 25 de enero de 2016

Bulk Insert Notes

How to Fix Error : 
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)".


Part of my format file is like this

10.0
59
1       SQLCHAR             2       20      ""   1     "RecordType"                        SQL_Latin1_General_CP1_CI_AS
2       SQLCHAR             2       50      ""   2     "FullName"                           SQL_Latin1_General_CP1_CI_AS
3       SQLCHAR             2       9       ""   3     "CompanyID"                         SQL_Latin1_General_CP1_CI_AS


Solution:
So I changed this "             2       " to "             0       "

10.0
59
1       SQLCHAR             0       20      ""   1     "RecordType"                         SQL_Latin1_General_CP1_CI_AS
2       SQLCHAR             0       50      ""   2     "FullName"                           SQL_Latin1_General_CP1_CI_AS
3       SQLCHAR             0       9       ""   3     "CompanyID"                          SQL_Latin1_General_CP1_CI_AS

Please notice the differences line per line 



/*****************************************************/
How to Fix Error : 
Msg 4823, Level 16, State 1, Line 3
Cannot bulk load. Invalid column number in the format file "C:\COMPANIES.fmt".

Format File is like this:

10.0
59
1       SQLCHAR             0       20      ""   1     [RecordType]                         SQL_Latin1_General_CP1_CI_AS
2       SQLCHAR             0       50      ""   2     FullName                             SQL_Latin1_General_CP1_CI_AS
3       SQLCHAR             0       9       ""   3     [CompanyID]                          SQL_Latin1_General_CP1_CI_AS
4       SQLCHAR             0       3       ""   4     [Column 3]                           SQL_Latin1_General_CP1_CI_AS

Solution:
Changed the Square Brackets for double quotes

10.0
59
1       SQLCHAR             0       20      ""   1     "RecordType"                         SQL_Latin1_General_CP1_CI_AS
2       SQLCHAR             0       50      ""   2     FullName                             SQL_Latin1_General_CP1_CI_AS
3       SQLCHAR             0       9       ""   3     "CompanyID"                          SQL_Latin1_General_CP1_CI_AS
4       SQLCHAR             0       3       ""   4     "Column 3"                           SQL_Latin1_General_CP1_CI_AS


/*****************************************************/
How to Fix Error : 
Msg 4862, Level 16, State 1, Line 3
Cannot bulk load because the file "C:\crane\COMPANIES.fmt" could not be read. Operating system error code (null).

Solution:
Open your format file press Ctrl-End you should be going to the last line.
If your last line is a column definition you need to go to the end of that line, press enter and Save it.
so you must have an EMPTY LAST LINE in your file.