Quantcast
Channel: beyondrelational.com
Viewing all articles
Browse latest Browse all 25

Import data - solving data convertion and truncation error

$
0
0

Often developers use Import wizard from SSMS or SSIS to import data from a text file into a table. You may or may not import it successfully based on the nature of the data.

Create a text file named test.txt with the following data

id|name|address
1|ramesh|12th road,chennai
2|nilesh|this is testing address and it has more than fifty characters: 4th cross street, adyar, chennai, tamil nadu, India

Now using an import wizard from SSMS, try to import this file to a table.

Right click on database-->Import data
Choose Data source as Flat file source, browse the file, Under the Data source tab, choose the columns and make sure that Row delimiter is {CR}{LF} and column delimiter as Vertical Bar {|}, click next and choose the destination as SQL Server native client 11.0, choose the relevant authentication mode and a database, click next and at last click Finish.

In the step named Executing, the status shows as error. Click on the error, it will pop-up a new window with the error message

 

- Executing (Error)

Messages

Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column "address" 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 "Source - test_txt.Outputs[Flat File Source Output].Columns[address]" failed because truncation occurred, and the truncation row disposition on "Source - test_txt.Outputs[Flat File Source Output].Columns[address]" specifies failure on truncation. A truncation error occurred on the specified object of the specified component.
(SQL Server Import and Export Wizard)

Error 0xc0202092: Data Flow Task 1: An error occurred while processing file "C:\test.txt" on data row 3.
(SQL Server Import and Export Wizard)

Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The PrimeOutput method on Source - test_txt returned error code 0xC0202092. The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing. There may be error messages posted before this with more information about the failure.
(SQL Server Import and Export Wizard)


So where is the problem?

Now go back to the initial step of this wizard (Choosing Data Source). Under Data Source click on Advanced, choose the column address. The output column width is 50 (by default all varchar columns will have width of 50), change it to 100 and do the same process. All data will get imported succesfully.

So kwwp this in mind while using a import wizard or SSIS and increase the width from default value of 50

 


Viewing all articles
Browse latest Browse all 25

Trending Articles