I am trying to import data from a utf-8 encoded flat file into SQL Server 2008 using SSIS. This is what the end of the row data looks like in Notepad++:

I have a couple more images showing what the file connection manager looks like:


You can see that the data shows correctly in the file connection manager preview. When I try to import this data, no rows import. I get an error message indicating that the row delimiter was not found. You can see in the file connection manager images that the header row delimiter and the row delimiter are both set to {LF}. This was sufficient to generate the correct preview, so I am lost to why it did not work to import. I have tried a number of things that have brought zero results:
- Tried using the Wizard import in SSMS…same results
- Tried using data conversion, no impact
- Tried setting the row delimiter to (0a), same results
[Flat File Source [582]] Warning: The
end of the data file was reached while
reading header rows. Make sure the
header row delimiter and the number of
header rows to skip are correct.
Thanks for looking at this and I really appreciate any help you can offer.
Cause:
SSIS fails to read the file and displays the below warning due to the column delimiter
Ç("c" with cedilla) andnotdue to the line delimiter{LF}(Line Feed).Here is a sample SSIS package that shows how to resolve the issue using
Script Componentand at the end there is another example that simulates your issue.Resolution:
Below sample package is written in
SSIS 2008 R2. It reads a flat file with row delimiter{LF}as a single column value; then splits the data usingScript Componentto insert the information into a table inSQL Server 2008 R2database.Use Notepad++ to create a simple flat file with few rows. The below sample file has Product Id and List Price information on each row separated by
Ças column delimiter and each row ends with{LF}delimiter.On the Notepad++, click
Encodingand then clickEncoding in UTF-8to save the flat file inUTF-8encoding.The sample will use an
SQL Server 2008 R2database namedSora. Create a new table nameddbo.ProductListPriceusing the below given script. SSIS will insert the flat file data into this table.Create an SSIS package using Business Intelligence Development Studio (BIDS) 2008 R2. Name the package as
SO_6268205.dtsx. Create a data source namedSora.dsto connect to the databaseSorain SQL Server 2008 R2.Right-click anywhere inside the package and then click
Variablesto view the variables pane. Create a new variable namedColumnDelimiterof data typeStringin the package scopeSO_6268205and set the variable with the valueÇRight-click on the
Connection Managersand clickNew Flat File Connection...to create a connection to read the flat file.On the
Generalpage of the Flat File Connection Manager Editor, perform the following actions:ProductListPriceFlat file connection manager to read product list price information.C:\Siva\StackOverflow\Files\6268205\ProductListPrice.txt{LF}from Header Row DelimiterColumn names in the first data rowColumnspageOn the
Columnspage of the Flat File Connection Manager Editor, verify that theColumn delimiteris blank and disabled. ClickAdvancedpage.On the
Advancedpage of the Flat File Connection Manager Editor, perform the following actions.LineData{LF}Unicode string [DT_WSTR]255Previewpage.On the
Previewpage of the Flat File Connection Manager Editor, verify that the displayed data looks correct and clickOK.You will see the data source Sora and the flat file connection manager ProductListPrice on the
Connection Managerstab at the bottom of the package.Drag and drop
Data Flow Taskonto the Control Flow tab of the package and name it asFile to database - Without Cedilla delimiterDouble-click the Data Flow Task to switch the view to the
Data Flowtab on the package. Drag and drop aFlat File Sourceon the Data Flow tab. Double-click the Flat File Source to openFlat File Source Editor.On the
Connection Managerpage of the Flat File Source Editor, select the Flat File Connection ManagerProductListPriceand click Columns page.On the
Columnspage of the Flat File Source Editor, check the columnLineDataand clickOK.Drag and drop a
Script Componentonto the Data Flow tab below the Flat File Source, selectTransformationand clickOK. Connect the green arrow from Flat File Source to Script Component. Double-click Script Component to openScript Transformation Editor.Click Input Columns on Script Transformation Editor and select
LineDatacolumn. Click Inputs and Outputs page.On the
Inputs and Outputspage of the Script Transformation Editor, perform the following actions.SplitDataOutputAdd Column. Repeat this again to add another column.ProductIdUnicode string [DT_WSTR]30On the
Inputs and Outputspage of the Script Transformation Editor, perform the following actions.ListPricenumeric [DT_NUMERIC]122On the
Scriptpage of the Script Transformation Editor, perform the following actions.User::ColumnDelimiterEdit Script...Paste the below C# in the Script Editor. The script performs the following tasks.
Çdefined in the variable User::ColumnDelimiter, the methodFlatFileInput_ProcessInputRowsplits the incoming value and assigns it to the two output columns defined in the Script Component transformation.Script component code in C#
Drag and drop
OLE DB Destinationonto the Data Flow tab. Connect the green arrow from Script Component to OLE DB Destination. Double-click OLE DB Destination to openOLE DB Destination Editor.On the
Connection Managerpage of the OLE DB Destination Editor, perform the following actions.Sorafrom OLE DB Connection ManagerTable or view - fast loadfrom Data access mode[dbo].[ProductListPrice]from Name of the table or the viewClick
Mappingspage on the OLE DB Destination Editor would automatically map the columns if the input and output column names are same. ClickOK.Data Flow tab should look something like this after configuring all the components.
Execute the query
select * from dbo.ProductListPricein the SQL Server Management Studio (SSMS) to find the number of rows in the table. It should be empty before executing the package.Execute the package. You will notice that the package successfully processed 9 rows. The flat file contains 10 lines but the first row is header with column names.
Execute the query
select * from dbo.ProductListPricein the SQL Server Management Studio (SSMS) to find the 9 rows successfully inserted into the table. The data should match with flat file data.The above example illustrated how to manually split the data using Script Component because the Flat File Connection Manager encounters error when configured the column delimiter
ÇIssue Simulation:
This example shows a separate Flat File Connection Manager configured with column delimiter
Ç, which executes but encounters a warning and does not process any lines.Right-click on the
Connection Managersand clickNew Flat File Connection...to create a connection to read the flat file. On theGeneralpage of the Flat File Connection Manager Editor, perform the following actions:ProductListPrice_CedillaFlat file connection manager with Cedilla column delimiter.C:\Siva\StackOverflow\Files\6268205\ProductListPrice.txtSelect the flat file path.{LF}from Header Row DelimiterColumn names in the first data rowColumnspageOn the
Columnspage of the Flat File Connection Manager Editor, perform the following actions:{LF}Reset ColumnsÇAdvancedpageOn the
Advancedpage of the Flat File Connection Manager Editor, perform the following actions:ProductIdÇUnicode string [DT_WSTR]30ListPriceOn the
Advancedpage of the Flat File Connection Manager Editor, perform the following actions:ListPrice{LF}numeric [DT_NUMERIC]122OKDrag and drop a
Data Flow taskonto the Control Flow tab and name it asFile to database - With Cedilla delimiter. Disable the first data flow task.Configure the second data flow task with
Flat File SourceandOLE DB DestinationDouble-click the Flat File Source to open
Flat File Source Editor. On theConnection Managerpage of the Flat File Source Editor, select the Flat File Connection ManagerProductListPrice_Cedillaand click Columns page to configure the columns. ClickOK.Execute the package. All the components will display green color to indicate that the process was success but no rows will be processed. You can see that there are no rows numbers indication between the
Flat File SourceandOLE DB DestinationClick the
Progresstab and you will notice the following warning message.