Archive for July, 2012

Import Data from Text file fails in SQL 2005 with error 0xc02020a1

July 20, 2012

Why Can Fail?!

You export some data from a database table as a text file. You run the SQL Server Import and Export Wizard, wanting to import the data into a table with the EXACT SAME STRUCTURE. You go through the steps, click on finish to start running and “Boom!”, SQL Server 2005 hits you with error logs such as these:

Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column “Column 1” returned status value 4 and status text “Text was truncated or one or more characters had no match in the target code page.”.
(SQL Server Import and Export Wizard)

Error 0xc020902a: Data Flow Task 1: The “output column “Column 1″ (14)” failed because truncation occurred, and the truncation row disposition on “output column “Column 1″ (14)” specifies failure on truncation. A truncation error occurred on the specified object of the specified component.
(SQL Server Import and Export Wizard)

Why Like That?!

This probably has something to with the length of your table columns. Although the source and destination both have a length of e.g. 128.  in the SQL Server Import and Export Wizard they only set the column length into the temp tables they use to length 50  by default. (Huh?) If your data exceeds 50 characters, you will hit that error.


What To Do?!

After selecting “Flat File Source” as the Data source, look at the panel called “Advanced” on the left hand side of the wizard. Click on it, then you set manually set the length of the offending column(s) to whatever size you like. The property to change is called “OutputColumnWidth”


Where Got Say?!

The answer can be found here.

Hope this saves you the frustration of  wondering why SQL Server 2005 can’t even import a simple text file properly. 😉