0

It's working fine till the line " oleda.Fill(ds);" when debugger reach that line, it doesn't show any error or exception just throw back to the View (HTML Page). I'm unable to understand the source of exception. Can anyone please guide me.

 public class OledbRepository
    {
        private string _connectionString;

        public OledbRepository(string filePath)
        {
            _connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';";
        }

        public DataTable Invoke(string sheetName)
        {
            DataTable result;

            using (var connection = new OleDbConnection(_connectionString))
            {
                OleDbCommand cmd = new OleDbCommand("SELECT * FROM " + sheetName, connection);

                OleDbDataAdapter oleda = new OleDbDataAdapter() { SelectCommand = cmd };
                DataSet ds = new DataSet();
                oleda.Fill(ds);

                result = ds.Tables[0];
            }

            return result;
        }
    }
Okasha Momin
  • 191
  • 3
  • 15
  • 1
    At the view what kind of error do you see? Also just wrap it with a `try/catch` you should be able to see exception inside the catch. – panoskarajohn Dec 22 '19 at 10:39
  • Thank for try/catch suggestion... I got the error {"The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine."}. – Okasha Momin Dec 22 '19 at 10:51
  • Well...-> https://stackoverflow.com/questions/6649363/microsoft-ace-oledb-12-0-provider-is-not-registered-on-the-local-machine – panoskarajohn Dec 22 '19 at 10:54
  • but the problem still exists.. I have two different projects running on same OledbRepository but one is of .NetFrameWork MVC and the other one is .NetCore MVC It's working fine in old project (.NetFrameWork MVC) without any exception....but throwing an exception in .netCore project...is there any idea what is the main cause? – Okasha Momin Dec 22 '19 at 10:54
  • The provider's bitness counts. You need to reference the provider's version that matches your app's bitness. You can install the `ACE.OLEDB.16.0` version alongside the `ACE.OLEDB.12.0` version. – Jimi Dec 22 '19 at 11:05
  • ACE driver comes with microsoft office. If you have office you need to use the version of the office installed. If you do not have office installed than you need to download the runtime version of ACE. – jdweng Dec 22 '19 at 11:10
  • @jdweng You can either use the installed version or install *the another* (`ACE.OLEDB.16.0`, usually). You can have both and also use both. The build profile matters. – Jimi Dec 22 '19 at 13:28
  • Yes, I know you can have more than one version. I never implied only one version. I just meant you need at least one. – jdweng Dec 22 '19 at 13:34

0 Answers0