SQL Server - BulkInsert from positional .txt using .xml fileformat error -



SQL Server - BulkInsert from positional .txt using .xml fileformat error -

good afternoon all, have scenario: using sql server 'bulkinsert' command insert info in table positional (.txt) file. use, define construction of file, .xml file defines position (and lenght) of fields , names.

these 2 sample rows of .txt positional file:

aaa111111surname 1 name 1 bbb222222surname 23 name 99

my .xml format file defined below:

<?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="charfixed" length="3" /> <field id="2" xsi:type="charfixed" length="6" /> <field id="3" xsi:type="charfixed" length="20" /> <field id="4" xsi:type="charfixed" length="20" /> <field id="5" xsi:type="charterm" terminator="\r\n" /> </record> <row> <column source="1" name="alfacode" xsi:type="sqlnvarchar"/> <column source="2" name="numericcode" xsi:type="sqlnvarchar"/> <column source="3" name="surname" xsi:type="sqlnvarchar"/> <column source="4" name="name" xsi:type="sqlnvarchar"/> </row> </bcpformat>

my sql server code is:

delete my_table mass insert my_table 'c:\directory\inputfile.txt' ( formatfile = 'c:\directory\formatfile.xml' )

but when run in sql server sp, have next error:

msg 4866, level 16, state 1, line 3 mass load failed. column long in info file row 1, column 58. verify field terminator , row terminator specified correctly. msg 7399, level 16, state 1, line 3 ole db provider "bulk" linked server "(null)" reported error. provider did not give info error. msg 7330, level 16, state 2, line 3 cannot fetch row ole db provider "bulk" linked server "(null)".

this has run until 2 months ago, wrong info introduced file , procedure failed. info inputfile.txt right again, procedure doesen't work checked more 1 time inputfile.txt, formatfile.xml and, sure, my_table, seems perfect.

i desperate because seems ok, compared old .xml files substiuted adding fields.

please reply asap , sorry if english language bad. don't esitate tell me other informations.

thanks all

i think it's input file must still wrong. (even though think fixed it).

in example, have 50 characters on line 1 before line break. xml says should have 49 chars! (3+6+20+20) sec line in illustration has 39 characters before linebreak.

it's worth opening txt file in text editor show line breaks. instance, in notepad++, go view -> show symbol -> show characters. can see cr , lf characters, verify there.

sql-server sql-server-2008 bulkinsert

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -