Click here to Skip to main content
13,288,869 members (54,705 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I am using the following code to import data using Excel sheet. It is working fine in localhost, but not in server. I d't know the reason. The file is storing in a folder, but the data fetching and saving in database is not happening. Is the server need to install the MS Excel ?.the oconn.Open() function is not happening,from their only the error is comming..Plz gve me a solution.
string extension = Path.GetExtension(FileUpload1.FileName);
                filename = DateTime.Now.ToString("dd-MM-yyyy") + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Minute + "_" + DateTime.Now.Millisecond + extension;
                FileUpload1.SaveAs(Server.MapPath("~/Account/PublishedRanklist/") + filename);
                string path = Server.MapPath("~/Account/PublishedRanklist/" + filename);
                OleDbConnection oconn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=Excel 8.0");
                    OleDbCommand ocmd = new OleDbCommand("select * from [Sheet1$]", oconn);
                    OleDbDataReader odr = ocmd.ExecuteReader();
                    while (odr.Read())
                   {       int Regno=valid(odr, 0);

protected string valid(OleDbDataReader myreader, int stval)//if any columns are found null then they are replaced by zero
            object val = myreader[stval];
            if (val != DBNull.Value)
                return val.ToString();
                return Convert.ToString(0);
Posted 16-Jan-14 22:11pm
Updated 17-Jan-14 18:44pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

For reading the excel using Oledb you do not require Microsoft Excel to be installed.

Instead of using DataReader
OleDbDataReader odr = ocmd.ExecuteReader();

try using Datatable and check if data are getting filled in DataTable or not?
Member 9492907 17-Jan-14 4:08am
I am using the OleDbDataReader only. you can see it in my code. It is working fine in localhost, only in the server not working.
Deviprasad Das 17-Jan-14 4:27am
Then please check if "Microsoft.Jet.OLEDB.4.0" adapter is registered in the server or not.
Member 9492907 17-Jan-14 4:35am
Can u plz tell me how to check it
Member 9492907 17-Jan-14 7:53am
oconn.Open(); is not happening...How to solve it in server
Gopi Kishan Mariyala 17-Jan-14 23:46pm
Check if the server has folder access permissions. Is the file located on server. Then check if the IIS has access to that folder
Member 9492907 18-Jan-14 2:31am
The IIS has the full permission to access the folder. anything need to install or something in the server
Gopi Kishan Mariyala 18-Jan-14 4:32am
What is the exact error message you are getting when you do Oconn.Open()

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171207.1 | Last Updated 18 Jan 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100