0

I created a simple console application to test the ability to push data from an excel file into a dataset and it works fine on my local machine (win 8.1). However, when I move the project to server 2012, and run it, it always returns an empty dataset. I'm a little suspicious their is a local policy the account needs, however the account is a local admin.

class Class1
{
    public DataSet ReturnExcelDataTable(string fileName)
    {
        DataSet dsImport = new DataSet();
        DataSet ds = new DataSet();
        string strConn;

        strConn = "Provider=Microsoft.ACE.OLEDB.12.0;" +
                   "Data Source=" + fileName +
                   ";Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1\";";

        try
        {
            OleDbDataAdapter cmd = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);
            cmd.Fill(dsImport);
        }
        catch (Exception ex)
        {

        }

        return dsImport;
    }


}


    static void Main(string[] args)
    {
        Class1 xls = new Class1();

        string fileName = @"c:\temp\targets\test3.xlsx";
        DataSet dt = xls.ReturnExcelDataTable(fileName);
        foreach (DataRow dr in dt.Tables[0].Rows)
        {
            Console.WriteLine(dr[0]);
            Console.ReadKey();
        }


    }
Dylan
  • 1
  • 4
  • The specific error message is IndexOutOfRangeException was unhandled. Cannot find Table 0. Of course the dataset that gets returned is empty. – Dylan May 26 '15 at 20:29
  • 1
    This error happens when you try to use dt.Tables[0] but this is probably too late. Instead your code has an empty try/catch that is obscuring the real problem. Do not put empty try/catch. Remove it in the ReturnExcelDataTable method and tell us what is the real error message – Steve May 26 '15 at 20:41
  • Bingo, I got:The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine. – Dylan May 26 '15 at 20:47
  • And this is a totally different problem. You need to compile your app for x86 platform (or for the same bitness of the current ACE OLEDB provider) – Steve May 26 '15 at 20:48
  • [This answer](http://stackoverflow.com/a/17716238/1197518) explains the issue – Steve May 26 '15 at 20:51
  • Ok, thanks. When I moved the code into my main project, it now says OleDBException was unhanlded by user code. – Dylan May 26 '15 at 21:04

0 Answers0