Solved

BUL:K INSERT OF UNICODE FILE

Posted on 2002-04-30
6
343 Views
Last Modified: 2008-02-01

I am trying to use BULK INSERT to populate a table in a SQL Server 2000 database from a unicode file.  I am using the following:

BULK INSERT tblTable FROM 'E:\File.txt'
 WITH (
     CHECK_CONSTRAINTS,
     DATAFILETYPE = 'widechar',
     FIELDTERMINATOR = '\0',
     FIRSTROW = 2,
     KEEPIDENTITY,  
     MAXERRORS = 0,  
     ROWTERMINATOR = '\0\n',
     TABLOCK )

but I'm getting an error - "Bulk insert data conversion error (truncation) for row 2, column 1 (fkColumnName)."

The same paramaters (except DATAFILETYPE) for BULK INSERT work fine when the file is ASCII. I have tried \0\0 for FIELDTERMINATOR and \0\0\n for ROWTERMINATOR but this doesn't work.

Anybody any ideas?

0
Comment
Question by:DJWalker
  • 3
  • 3
6 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6980661
I think that the codepage option might help.

CODEPAGE [ = 'ACP' | 'OEM' | 'RAW' | 'code_page' ]

Specifies the code page of the data in the data file. CODEPAGE is relevant only if the data contains char, varchar, or text columns with character values greater than 127 or less than 32.

CODEPAGE value Description
ACP Columns of char, varchar, or text data type are converted from the ANSI/Microsoft Windows® code page (ISO 1252) to the SQL Server code page.
OEM (default) Columns of char, varchar, or text data type are converted from the system OEM code page to the SQL Server code page.
RAW No conversion from one code page to another occurs; this is the fastest option.
code_page Specific code page number, for example, 850

Now, if the column in the table is shorter than the data to be inserted, this would explain the "truncation" error...
As the row/columns are indicated, I would look at the file to see which are the differences to the previous rows...

CHeers


0
 

Author Comment

by:DJWalker
ID: 6980781

Thanks for a quick reply.

I have tried your suggestion, but it makes no difference.

One of my tables does have a char column in it, but apart from the NULL terminator, there are no characters in the file greater than 127 or less than 32.

The row and column are the first row and the first column being inserted, the column being a single digit in one case.

The unicode and ASCII data are both the same, ie ASCII and unicode versions of the same file so I think the data itself should be OK.




0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6980813
could you either post the first lines of the file here, or send it to me?

What i suspect is that the value in the file is longer than what is defined in the database...

CHeers
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:DJWalker
ID: 6982850
I'll send the file by e-mail.

Thanks.
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 300 total points
ID: 6985218
First, i can confirm that i get also the problems with your files...
BUT if I use BCP:
bcp testdatabase.dbo.tbltable in c:\tblTable_uni.txt -F2 -w -t\0 -r\0\n -Usa -P
Everything is fine and dandy...

If nothing else works, I can only suggest to use that...

You might try to use the FORMATFILE option, using the parameters of bcp above into a file...

CHeers
0
 

Author Comment

by:DJWalker
ID: 6985461

Thanks for your help.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MS SQL - Rotating Values in SQL 9 53
SQL Select Statement 2 22
My Query is not giving correct result. Please help 5 30
Help with Sorting Full Text results 2 14
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now