Search code examples
sql-serverfileimportexportflat-file

Import DAT file content to SQL Server table using Import Export Wizard - Error


I have .DAT file which looks like below format[no column name or header, only data]: || is the separator; so, I have 20 fields.

worth||8000||AC8000||Tal||100||IN||O||2014-01-09 00:00:00||||N||N||N||Y||2014-01-09 00:00:00||Y||19991011||N||Internal||||N

My SQL DB table also has 20 columns.

When I'm using import export wizard, I'm getting error as below:

 - Executing (Error)
 Messages
  Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column "Column 0" 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 0" (10)" failed because truncation occurred, and the truncation row disposition on "output column "Column 0" (10)" 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 "H:\servername\Account.20151201.dat\Account.20151201.dat" on data row 109.
 (SQL Server Import and Export Wizard)

 Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on component "Source - Account_20151201_dat" (1) 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)

Note: I have all columns in DB table has 255 char.

Please let me know, how to resolve this problem? How can I successfully import it to my DB.


Solution

  • Configure your flat file source with the correct data type and data length. Seems that data received from the file is more than the data length you have defined leading to truncation.

    Your first error shows the text you are trying to import in one of the columns is larger than the size of the column in your data base(in destination db table), So change the column size to be larger in your DB: ALTER your TABLE, set more characters for the column VARCHAR(255),

    For the second error it seems maybe some of row in you DAT file have less or more than 20 columns which don't match with your table, may bi in row 109 as reported in one of the error. Hope it helps