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();
}
}