Click here to Skip to main content
15,889,403 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
I have one excel file with more than 10 lacks records,
I am using Ado dot net for read this excel (Microsoft.ACE.OLEDB.12.0)

when i am reading this file through C# then i am getting(or reading) only 24 thousand rows (for Bulk Insert)


when I am hosting this on my local system (IIS 6)(by using "Localhost") ,I am able to read all rows(10 lacks rows)

if i am hosting the same on my main server (IIS 7), then i am able to read only 24 thousand rows only

When I CONVERTED EXCEL TO CSV THEN AGAIN CSV to EXCEL after i tryied to upload then I can read 31 thousand rows(no of row increased)



Could any one please help me to solve this problem


1 My connection string for reading excel is

C#
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0;HDR=YES; IMEX=0;\"";



2
C#
OleDbCommand xlCmd = new OleDbCommand("SELECT * FROM [" + sheetName + "]", xlCon);
            xlCmd.CommandType = CommandType.Text;
            OleDbDataReader xlReader = xlCmd.ExecuteReader();


3 my time out more than 6000

[EDIT]CODE tags added - LOSMAC[/EDIT]
Posted
Updated 2-May-12 22:18pm
v5
Comments
Maciej Los 29-Apr-12 10:30am    
Try to increase connection timeout and try to load data from csv. Let us know about results.
Meajas 2-May-12 2:16am    
@losmac thanks for the replay.

But

I already tried to upload from CSV it's working fine. But my problem is this is already delivered project and it's working fine with less than 15 mb data so i can't suggest for CSV. I need to upload data from excel :(.
Meajas 2-May-12 3:06am    
one of main thing is, i am getting this problem only with one particular file.
today i tried to upload another file (but it's column names are different)
and
it's size was : 80.4 MB ,
No of Rows was : 830732 Rows
There was no problem for uploading this file
File transaction timing was : 9 minute
Remaining process (Bulk insert and Distribution of data to dimension table ) : 8 minute.

I have one Doubt, is this the problem because of maximum error range...??

If so where i need to give this...???
Maciej Los 2-May-12 8:08am    
It's very interesting... I'm working with multiple files which size is between 40 - 125 MB. You use IMEX, so please, see a note from connectionstrings.com site:
"Treating data as text(...) Use this one when you want to treat all data in the file as text, overriding Excels column type "General" to guess what type of data is in the column.
If you want to read the column headers into the result set (using HDR=NO even though there is a header) and the column data is numeric, use IMEX=1 to avoid crash.

To always use IMEX=1 is a safer way to retrieve data for mixed data columns. Consider the scenario that one Excel file might work fine cause that file's data causes the driver to guess one data type while another file, containing other data, causes the driver to guess another data type. This can cause your app to crash."
Meajas 3-May-12 4:18am    
@losmac Thank you so much for the Valuable information,

Yes the problem was with IMEX=1 ,Yesterday I got the solution But I forgot to update(without knowing proper information, i changed to IMEX=1).
But now you explained it well....!!!!

once again Thanks for your Help losmac....!!!! :)

1 solution

Moved from comment
It's very interesting... I'm working with multiple files which size is between 40 - 125 MB. You use IMEX, so please, see a note from connectionstrings.com site:
"Treating data as text(...) Use this one when you want to treat all data in the file as text, overriding Excels column type "General" to guess what type of data is in the column.
If you want to read the column headers into the result set (using HDR=NO even though there is a header) and the column data is numeric, use IMEX=1 to avoid crash.

To always use IMEX=1 is a safer way to retrieve data for mixed data columns. Consider the scenario that one Excel file might work fine cause that file's data causes the driver to guess one data type while another file, containing other data, causes the driver to guess another data type. This can cause your app to crash."
 
Share this answer
 
Comments
VJ Reddy 4-May-12 12:45pm    
Good answer. +5
Maciej Los 4-May-12 13:25pm    
Thank you, VJ ;)
bineet dungdung 6-Mar-13 15:42pm    
Hi,i am reading an Excel source file having mixed data formats and there are many rows which are generated through calculations in the sheet. I applied the IMEX=1 and HDR = No,It didnt solve the purpose .Further I also changed the TYPEGUESSROWS key from 8 to 0 and the ImportMixedTypes to Text in the registry location HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\12.0\Access Connectivity Engine\Engines\Excel .
It still does not read after 160 rows.
Please Help me on this .
Maciej Los 6-Mar-13 15:45pm    
Please, put this comment as a question.
bineet dungdung 6-Mar-13 15:55pm    
I have asked it as question . Thank you for reminding me. The question subject is IMEX = 1, HDR = No still does help reading excel file with mixed data formats ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900