Hello SQL Buddies,
I am trying to run a BULK insert.
Here is my code:
Code start:
use Lagerliste
drop table Import
use Lagerliste
create table Import
(
TOTALQTY float null,
PARTNO nvarchar (255) null,
[DESC] nvarchar (255) null,
CO nvarchar (255) null,
BIN nvarchar (255) null,
PRICE float null,
DISCOUNT nvarchar (255) null,
LASTPURC nvarchar (255) null,
AGECODE nvarchar (255) null,
MANFPART nvarchar (255) null
)
use Lagerliste
bulk
insert Import
from 'D:\FTP\RG\Stockfile.csv'
with
(
formatfile = 'D:\FormatFile\test.xml',
Errorfile = 'D:\FormatFile\error.txt'
)
Code stop..
My format file code is here:
Code start:
<?xml version="1.0"?>
<BCPFORMAT xmlns = "http://schemas.microsoft.com/sqlserver/2004/bulkload/format"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RECORD>
<FIELD ID="1" xsi:type="CharTerm" TERMINATOR= ',"' />
<FIELD ID="2" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '","' />
<FIELD ID="3" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '","' />
<FIELD ID="4" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '","' />
<FIELD ID="5" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '",' />
<FIELD ID="6" xsi:type="CharTerm" TERMINATOR= ',"' />
<FIELD ID="7" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '","' />
<FIELD ID="8" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '","' />
<FIELD ID="9" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '","' />
<FIELD ID="10" xsi:type="CharTerm" MAX_LENGTH="255" TERMINATOR= '"' />
</RECORD>
<ROW>
<COLUMN SOURCE="1" NAME="TOTALQTY" xsi:type="SQLFLT8"/>
<COLUMN SOURCE="2" NAME="PARTNO" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="3" NAME="DESC" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="4" NAME="CO" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="5" NAME="BIN" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="6" NAME="PRICE" xsi:type="SQLFLT8"/>
<COLUMN SOURCE="7" NAME="DISCOUNT" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="8" NAME="LASTPURC" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="9" NAME="AGECODE" xsi:type="SQLNVARCHAR"/>
<COLUMN SOURCE="10" NAME="MANFPART" xsi:type="SQLNVARCHAR"/>
</ROW>
</BCPFORMAT>
Code stop..
If i run the code it says:
Msg 4832, Level 16, State 1, Line 20
Bulk load: An unexpected end of file was encountered in the data file.
Msg 7399, Level 16, State 1, Line 20
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 20
Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".
And the error file says:
Row 473629 File Offset 42503226 ErrorFile Offset 0 - HRESULT 0x80004005
If i then in my bulk insert adds: "Lastrow = '473629' it works all fine. So it will mean that it gets an error at the last line where there is no more data? But this sql query should run every day, so i have to do so it dont gets the error.
Can someone help me?
Looking forward to an answer, i hope someone have a solution.
Regards Christian.