Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am using the following code to convert Excel work sheet to datataable. It is working in my local machine from code. But after deployment in Windows 2003 server this is not reading .XlSX files. Also, I have Office 2007 and VSTS 2010 in Windows Server. Any ideas on this please.
C#
static System.Data.DataTable lFnConvertWorkSheetToDatatblae(string lStrFileName, string aStrWorkSheetName)
       {

           string lStrConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + lStrFileName + ";Extended Properties=Excel 8.0;";

           OleDbConnection lObjConn = null;
           OleDbDataAdapter lObjSheetAdapter = null;

           try
           {
               System.Data.DataTable lDTSheetData = new System.Data.DataTable();

               using (lObjConn = new OleDbConnection(lStrConnectionString))
               {
                   lObjConn.Open();

                   lObjSheetAdapter = new OleDbDataAdapter("select * from [" + aStrWorkSheetName + "$]", lObjConn);

                   lObjSheetAdapter.Fill(lDTSheetData);

               }

               return lDTSheetData;
           }
           catch (Exception)
           {
               return null;
           }
           finally
           {

               if (lObjSheetAdapter != null)
               {
                   lObjConn.Close();
                   lObjSheetAdapter.Dispose();
               }

               if (lObjConn != null)
               {
                   lObjConn.Dispose();
               }

           }
       }
Posted
Updated 6-Oct-11 22:50pm
v2
Comments
CodingLover 7-Oct-11 5:00am    
Did you end-up with an error?
Sreenath Gv 7-Oct-11 5:18am    
yeah..cant read files..
André Kraak 7-Oct-11 14:15pm    
What are the values of the parameters lStrFileName and aStrWorkSheetName?
Sreenath Gv 10-Oct-11 1:20am    
its name of file and the worksheet name in that file..

Hi,

I am getting this error at server, but the same works in my local machine.

"The Microsoft Jet database engine cannot open the file ''.
It is already opened exclusively by another user, or you need permission to view its data."
 
Share this answer
 
hi,

what's the error message you get ? is it "Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine" ??

since it's working on local and not on the server, and Office 2007 is installed on your server, probably it's a 32/64bits problem.

the obvious guess is that your your server is 64bit and your local system is 32bits,

follow this tutorial The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine to make Jet OLEDB run on a 64bits machine.

hope this helps.
 
Share this answer
 
v2

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