you can use the following code to see if there is any problem to connect an excel file on your server. If there is no problem with that, you should look for file existence or permissions etc.
I expect that an exception is thrown in case of such file issues, but you say no exception is caught. I still advice you to log all exceptions into some location (a text file, database etc) to see what is going on, instead of displaying them as error messages on UI.
using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OleDbTest1
{
class Program
{
static void Main()
{
try
{
Test1();
Test2();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadKey();
}
private static void Test2()
{
string connStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}; Extended Properties=""Excel 8.0;HDR=No;IMEX=1""";
connStr = string.Format(connStr, @"D:\tmp\book1.xls");
using (OleDbConnection conn = new OleDbConnection(connStr))
{
conn.Open();
Console.WriteLine("db='{0}' ds='{1}'", conn.Database, conn.DataSource);
}
}
private static void Test1()
{
OleDbDataReader reader = OleDbEnumerator.GetRootEnumerator();
DisplayData(reader);
}
static void DisplayData(OleDbDataReader reader)
{
while (reader.Read())
{
if (!reader["SOURCES_NAME"].ToString().Contains("Jet"))
continue;
for (int i = 0; i < reader.FieldCount; i++)
{
Console.WriteLine("{0} = {1}",
reader.GetName(i), reader.GetValue(i));
}
Console.WriteLine("==================================");
}
}
}
}