SSIS read flat file skip first row - sql-server

First of all, I did spend quite some time on research, and I know there are many related questions, though I can't find the right answer on this question.
I'm creating a SSIS package, which does the following:
1. Download and store CSV file locally, using HTTP connection.
And 2. Read in CSV file and store on SQL Server.
Due to the structure of my flat file, the flat file connection keeps giving me errors, both in SSIS as in the SQL Import Wizard.
The structure of the file is:
"name of file"
"columnA","columnB"
"valueA1","valueB1"
"valueA2","valueB2"
Hence the row denominator is end of line {CR}{LF} and the column denominator is a comma{,}, with text qualifier ".
I want to import only the values, not the name of the file or the column names.
I played around with the settings and got the right preview with the following settings (see image below)
- Header rows to skip: 0
- Column names in the first data row: no
- 2 self-configured columns (string with columnWidth = 255)
- Data rows to skip: 2
When I run the SSIS Package or SQL Import Wizard I get the following error:
[SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED. The
PrimeOutput method on Flat File Source returned error code 0xC0202091.
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.
I can't figure out what goes wrong and what I can do to make this import work.

If you want to skip the file name and the column names, you need to set Header Rows to skip to 2. You should also check whether the file actually uses line feeds (LF) instead of CR+LF. Checking the line breaks in a text editor isn't enough to detect the difference, as most editors display correctly files with both CR+LF or LF.
You can check the results of your settings by clicking on the "Preview" button in your flat file source. If the settings are correct, you'll see a grid with your data properly aligned. If not, you'll get an error, or the data will be wrong in some way, eg a very large number of columns, column names in the first data row etc

Related

SSIS Ignore Blank Lines

I get the following SSIS error message when my source file has blank lines at the end of the file. I don't care about the blank lines as they don't affect the overall goal of pumping data from a text file to a database table. I'd like to ignore this message or, if its easier, configure SSIS to ignore blanks.
<DTS:Column DTS:ID="96" DTS:IdentificationString="Flat File Source.Outputs[Flat File Source Error Output].Columns[Flat File Source Error Output Column]"/>
I found a similar question below, but the solution isn't an SSIS one, its one that preprocesses the text files which would be my least favorite solution.
SSIS Import Multiple Files Ignore blank lines
If you want to exclude records with blank values you can use the Conditional Split. Add it between you source file and your destination.
The expression can be like below :
ISNULL(Col1) && ISNULL(Col2) && ISNULL(Col3) ...
Name the output as Remove Blank Lines. When connecting your Conditional Split to your destination, SSIS will ask you what output the split component that needs to be returned. In this case chose the Conditional Split Default Output to get the entire records without the blank values.
You can enable Data Viewer before and after the conditional split to see the filtered output.

Text Was Truncated or One or More Characters Has No Match in the Target Code Page

For the life of me, I cannot seem to get past the following error:
Error: 0xC020901C at Import Data - APA, APA Workbook [2]: There was an error with APA Workbook.Outputs[Excel Source Output].Columns[Just] on APA Workbook.Outputs[Excel Source Output]. The column status returned was: "Text was truncated or one or more characters had no match in the target code page.".
Error: 0xC020902A at Import Data - APA, APA Workbook [2]: The "APAC Workbook.Outputs[Excel Source Output].Columns[Just]" failed because truncation occurred, and the truncation row disposition on "APA Workbook.Outputs[Excel Source Output].Columns[Just]" specifies failure on truncation. A truncation error occurred on the specified object of the specified component."
I have an SSIS package that is trying to load data from an Excel file into a SQL Server table. I understand SSIS takes a "Snapshot" of the data and uses this to build the column sizes. My database column for this column is: nvarchar(512).
So some things I have done to try and rectify this are as follows:
Added "IMEX=1" to the extended properties of the Excel Connection string
Created an Excel file with 10 rows and each row has 512 characters in this "Just" column so that SSIS will recognize the size
Went into the Advanced Editor for the Source, then "Input and Output Properties". Then went to the Just column and changed DataType to "Unicode String [DT_WSTR] and changed the Length to 512
After I did the above, I ran the code and the 10 rows of data were imported with no issue. But when I run it against the real Excel file, the error appears again.
I have found that if I add a column to find the character length of the column, then sort by that, putting the largest first, the code works. But if the file is as sent by the user, it errors out
I would appreciate any help on how to solve this, as all of my Google searches state the above would work, but unfortunately it is not.

Non-obvious truncation error during flat file import in SSIS "on data row 387"

While trying to implement Hadi's the solution to my question about import to SSIS the file with max filename in the folder, I encountered the following error:
Data Flow Task, Flat File Source [28]: Data conversion failed. The data conversion for column ""AsofDateTime"" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.
Data Flow Task, Flat File Source [28]: The "Flat File Source.Outputs[Flat File Source Output].Columns["AsofDateTime"]" failed because truncation occurred, and the truncation row disposition on "Flat File Source.Outputs[Flat File Source Output].Columns["AsofDateTime"]" specifies failure on truncation. A truncation error occurred on the specified object of the specified component`
An error occurred while processing file "\Share\ABC_DE_FGHIJKL_MNO_PQRST_U-1234567.csv" on data row 387.
I spent hours on trying to find out what is specific about "row 387", playing this and that, removing and changing the source data, but did not get a hint at all - still the same error. SSIS package worked OK with explicitly specified filename, and the script correctly picks up the file with max filename but these parts simply do not work together, resulting in above error.
Answer: While the LAST file should be imported, SSIS takes table headers from the FIRST file in the folder.
Newer file versions were changed as per discussions with client, some columns were removed.
Solved by cleaning up older .csv file versions from import folder.

Error importing data from CSV with OpenRowset in SQL Server - Mysterious value of "S7"

I have a file dump which needs to be imported into SQL Server on a daily basis, which I have created a scheduled task to do this without any attendant. All CSV files are decimated by ',' and it's a Windows CR/LF file encoded with UTF-8.
To import data from these CSV files, I mainly use OpenRowset. It works well until I ran into a file in which there's a value of "S7". If the file contains the value of "S7" then that column will be recognized as datatype of numeric while doing the OpenRowset import and which will lead to a failure for other alphabetic characters to be imported, leaving only NULL values.
This is by far I had tried:
Using IMEX=1: openrowset('Microsoft.ACE.OLEDB.15.0','text;IMEX=1;HDR=Yes;
Using text driver: OpenRowset('MSDASQL','Driver=Microsoft Access Text Driver (*.txt, *.csv);
Using Bulk Insert with or without a format file.
The interesting part is that if I use Bulk Insert, it will give me a warning of unexpected end of file. To solve this, I have tried to use various row terminator indicators like '0x0a','\n', '\r\n' or not designated any, but they all failed. And finally I managed to import some of the records which using a row terminator of ',\n'. However the original file contains like 1000 records and only 100 will be imported, without any notice of errors or warnings.
Any tips or helps would be much appreciated.
Edit 1:
The file is ended with a newline character, from which I can tell from notepad++. I managed to import files which give me an error of unexpected end of file by removing the last record in those files. However even with this method, that I still can not import all records, only a partial of which can be imported.

issues importing .tsv to sql Server

I am trying to simply import a .tsv (200 column, 400,000 rows) to Sql Server.
I get this error all the time (always with a different column):
Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column "Column 93" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.".
Even though I explicitly:
So, I found myself, going back, and changing the Output (500 for this case):
Is there a way to change all OutputColumnWidth to like ‘max’ at once?! I have 200 columns I can't wait for it to fail and go back and change it for each failed column... (I do not care about performance, any data type is the same for me)
You could try opening the code view of your SSIS package and doing a ctrl-H replace of all "50" to "500". If you have 50's you don't want to change to 500 then look at the code and make the replacement more context-specific.

Resources