Virgil_R
Virgil_R

Reputation: 71

Cannot import long text from Excel to SQL Server using SSIS

Environment:

In Excel I formated the cell as "Text" and I also filled up the 2nd and 3rd rows with some super-long dummy text... (1st row is title row)

When I go to Excel Source/Advanced editor, I can set the Output to Unicode text stream [DT_NTEXT] or anything else but the External column cannot be changed to something else than Unicode string [DT_WSTR] (255 characters) despite the setting in registry that normally should allow it and despite having super-long strings in first two rows (other than the 1st row which holds the field names)

Then of course when I try to execute the SSIS task it throws a normal truncation error.

Question: What I am doing wrong or what else should be done here to actually be able to import the data? By the way, this is supposed to be automated at some point.

Upvotes: 1

Views: 2249

Answers (1)

Hadi
Hadi

Reputation: 37313

Since an Excel workbook is not a database, the OLE DB provider tries to detect the most relevant metadata from the Excel worksheet and read it as tabular data, which is mostly inaccurate when handling medium and large Excel files. After spending years on creating SSIS packages, I will convert the Excel file to a CSV file and import it using a Flat File Connection Manager instead. Or I will use a C# script to import the data.

I. Converting Excel to CSV

You can automate the process of converting Excel to CSV using a C# script:

After converting the Excel file to a CSV file, you can dynamically import it using a Flat File Connection Manager:

II. Using a C# script

It is good to check the following class, which is a part of the SchemaMapper project:

Besides, a step-by-step guide on how to use this library can be found in the following link:


III. Editing the Excel connection string

If you don't have the choice to convert Excel to flat files, then you can force the Excel connection manager to ignore headers from the first row by adding IMEX=1 to tell the OLEDB provider to specify data types from the first row (which is the header - all string most of the time).

To edit the connectionstring property, click on the Excel Connection Manager and press on the F4 key. In the Properties Tab, you can edit the connectionstring property.

IV. Changing columns length from advanced editor

Try changing the Excel Source column metadata from the advanced editor:


Importing Excel using SSIS may cause a headache! You can check the following question:

Upvotes: 4

Related Questions