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.
My unicode file has been created by saving my ASCII file
as a 'Unicode text file' in Wordpad.
Anybody any ideas?
I can't use notepad because it destroys the null
terminators, whereas WordPad doesn't.
BULK INSERT will successfully import a comma terminated
file converted to Unicode in WordPad, it just won't do it
with the NULL terminated file.
The problem seems to be simply that BULK INSERT won't work
with null terminated unicode files.
I can provide the files, SQL statements and files to
enable you to reproduce the problem if you like. Would you
like me to email them to you?
Darren
>-----Original Message-----
>Hi Darren,
>
>My name is Simon Liao. Thank you for using Microsoft
support.
>
>If I understand this issue correctly, you got an error
when you tried to use BULK
>INSERT to populate a table in a SQL Server 2000 database
from a Unicode file.
>
>First, I would like you to try to convert the text file
in Notepad, not the WordPad.
>Try to convert the text file in Unicode format in Notepad
and then re-try the Bulk
>Insert, what is the result?
>
>If it does not resolve this issue, you may need to
provide me with the following
>items, thus I can reproduce the issue on my machine:
>
>1. The table tblTable schema.
>
>2. The text file e:\file.txt
>
>3. The reproduce steps if possible
>
>Thanks,
>
>Sincerely,
>
>Simon Liao
>Microsoft Support
>
>This posting is provided "AS IS" with no warranties, and
confers no rights.
>Get Secure! - www.microsoft.com/security
>
>
>.
>
Thanks for your update.
yes, it would be much appreciated if you could provide the files, SQL statements
and files, so that I can reproduce this issue on my side. However, you do not need
to send me directly, you can attach it to your post.
Look forward to hearing from you.
To reporoduce the problem, create the following table:
CREATE TABLE [tblTable] (
[Column1] [int] NOT NULL ,
[Column2] [Decimal] (18,2) NOT NULL ,
[Column3] [char] (2) COLLATE Latin1_General_BIN
NOT NULL ,
[Column4] [datetime] NOT NULL)
From the following BULK INSERT statements, the first 2
will succeed, the 3rd will fail.
-- ASCII file, null terminators
BULK INSERT tblTable FROM 'E:\tblTable.txt'
WITH (
CODEPAGE = 'ACP',
CHECK_CONSTRAINTS,
FIELDTERMINATOR = '\0',
FIRSTROW = 2,
KEEPIDENTITY,
MAXERRORS = 0,
ROWTERMINATOR = '\0\n',
TABLOCK )
-- Unicode file, comma terminators
BULK INSERT tblTable FROM 'E:\tblTable_uni2.txt'
WITH (
DATAFILETYPE = 'widechar',
CODEPAGE = 'ACP',
CHECK_CONSTRAINTS,
FIELDTERMINATOR = '\,',
FIRSTROW = 2,
KEEPIDENTITY,
MAXERRORS = 0,
ROWTERMINATOR = '\,\n',
TABLOCK )
-- Unicode file, null terminators
BULK INSERT tblTable FROM 'E:\tblTable_uni.txt'
WITH (
DATAFILETYPE = 'widechar',
CODEPAGE = 'ACP',
CHECK_CONSTRAINTS,
FIELDTERMINATOR = '\0',
FIRSTROW = 2,
KEEPIDENTITY,
MAXERRORS = 0,
ROWTERMINATOR = '\0\n',
TABLOCK )
Kind regards,
Darren
>.
>
Just wanted to let you know that I can reproduce this issue on my side with
the files you kindly provided and need more research on it. I will get back to
you as soon as possible.
Would it be possible for you to take a look and let me
know what you think?
Thanks
Ed
>-----Original Message-----
>Hi Darren,
>
>My name is Simon Liao. Thank you for using Microsoft
support.
>
>If I understand this issue correctly, you got an error
when you tried to use BULK
>INSERT to populate a table in a SQL Server 2000 database
from a Unicode file.
>
>First, I would like you to try to convert the text file
in Notepad, not the WordPad.
>Try to convert the text file in Unicode format in Notepad
and then re-try the Bulk
>Insert, what is the result?
>
>If it does not resolve this issue, you may need to
provide me with the following
>items, thus I can reproduce the issue on my machine:
>
>1. The table tblTable schema.
>
>2. The text file e:\file.txt
>
>3. The reproduce steps if possible
>
>Thanks,
>
>Sincerely,
>
>Simon Liao
>Microsoft Support
>
>This posting is provided "AS IS" with no warranties, and
confers no rights.
>Get Secure! - www.microsoft.com/security
>
>
>.
>
Sorry that I have not been able to response sooner.
After carefully researching on this error, it seems SQL Server does not support null as the terminator.
Based on SQL Server Books online (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dtsprog/dtsppropfl_2n09.asp), Typical values are
",", ";", tab and "|". Since it does not say that null value cannot be acted as the filed terminator, I tried to find some official documents for you, but
failed.
I know this isn't exactly what you wanted to hear, but I hope this helps some.
--- Simon Liao
I have put my opinions on the thread you mentioned in your post: Titled "Bcp
Unicode Problem" in the SqlServer.programming section.
Hope that helps!
--- Simon Liao
Based on SQL Server Books Online, SQL Server DOES support
a null terminator...
http://msdn.microsoft.com/library/default.asp?
url=/library/en-us/adminsql/ad_impt_bcp_0fqq.asp
I'll have to pre-filter my data and use tab as a
terminator to work around the bug. :0)
Thanks for your help anyway.
Darren
>.
>
I DO, however, have success by using bulk insert on flat unicode
datafiles the way you do. I will guess the problem is the terminators.
Try with FIELDTERMINATOR = ',' or '\t' and ROWTERMINATOR = '\n'.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Eventually I decided to use /t as a terminator (as you suggest) but this
meant filtering the data beforehand, something we didn't have to do when
using /0.
-------------------------------------
I) Unicode file created with notepad or wordpad (windows XP)
has the following properties::
1) 2-bytes header FF FE
2) 2-bytes field terminator, f.eks 09 00 for tab
3) 4-bytes end of line terminator, for example 0D 00 0A 00
4) all other characters are 2-bytes unicode
It can by loaded into SQL server database with
bcp testDB..test in c:\data\test.txt -w
or
BULK INSERT testDB..test
FROM 'c:\projects\test.txt'
WITH (FIRSTROW = 1,
DATAFILETYPE = 'widechar')
GO
I didn't find it possible to use format files with BULK INSERT of
Notepad created unicode files.
------------------------------------
II) Unicode file created with
bcp testDB..test out c:\data\test.txt
where I answered the prompts with nvarchar,0,10,\t and
nvarchar,0,10,\n (the unicode file had two text fields of 10 char)
has the following properties:
1) no header
2) 1-byte field terminator 09 for tab
3) 2-bytes end of line terminator 0D 0A
4) all other characters are 2-bytes unicode
It can not be loaded into an SQL server database with
bcp testDB..test in c:\data\test.txt -w
but it can by using a format file
bcp testDB..test in c:\data\test.txt -fc:\data\test.fmt
or
bcp testDB..test in c:\data\test.txt
where you answer the prompts, as you did exporting the data from the SQL
server.
With BULK INSERT data can be loaded with
BULK INSERT testDB..test
FROM 'c:\data\test.txt'
WITH (FORMATFILE = 'c:\projects\test.fmt',
FIRSTROW = 1,
DATAFILETYPE = 'char')
GO
NOTICE that DATAFILETYPE = 'char'!!!!
The format filen test.fmt looked like this
8.0
2
1 SQLNCHAR 0 10 "\t" 1 tekst1
SQL_Latin1_General_CP1_CI_AS
2 SQLNCHAR 0 10 "\r\n" 2 tekst2
SQL_Latin1_General_CP1_CI_AS