SQL Server Import Wizard cannot import fields containing more than 255 characters

I have been importing data from Excel to SQL Server using the SQL Server Import Wizard. Usually there is no problem but I have found a bug.

1. To reproduce: Try to import a column containing more than 255 characters text, optimistically set the destination datatype to nvarchar(max) and the failure options to “ignore” on error and “ignore” on truncation.

2. I expect the Wizard to run successfully; nvarchar(max) has a 2GB limit and if I exceed this (I don’t) then it should ignore the error and truncate anyway

3. Actually the Wizard fails with the error ”Text was truncated or one or more characters had no match in the target code page.”

This is a known bug to do with the way the wizard samples the source at the beginning. There are two workarounds,

    1. ensure that there is a row at the top of the record set with the maximum width OR
    2. You can increase the number of rows sampled by increasing the value of TypeGuessRows under the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel registry key. (from social.msdn)

I used A.

Things that didn’t work,

    • defining the table with the right field lengths first and assuming the wizard is not buggy
    • exporting to CSV and using flat file inport
    • anything to do with the code page, this is red herring.
About these ads

About Dr James Bayley

If you would like chat please contact me. My consultancy ElephantPM provides project management services including FogBugz training, project start-up and troubleshooting. Having developed successful software products for other people I decided to create my own and Keyapt SMS, which was created with Chris Saltmarsh is the first. You can follow me at blog.jamesbayley.com and @ElephantPM on Twitter.
This entry was posted in Infrastructure and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s