Search code examples
c#oledbadodb

Provider cannot be found. It may not be properly installed. To connect excel 2016


I am trying to read from Excel 2016 file using

strConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strXLPath + ";Extended Properties=\"Excel 12.0;HDR=YES;\";";.

I am using ActivexObject and ADODB.Connection to open the connection to excel file. I am getting

Provider cannot be found. It may not be properly installed

error. I am using c# in .Net 3.5, Access Database Engine 2010 (64 bit) and Office 2016(64 Bit) and windows 7(64 bit) and Visual Studio 2008. Please help me. I've searched so much but couldn't find any solution for this. I'm attaching my code and the error image.ADODB error.

<script type="text/javascript" language="javascript"> 
    function IsXLValid() {


        var strXLPath = document.getElementById('<% =FileUpload.ClientID%>').value

        var len = strXLPath.length;

        if (len == 0) {
            alert("Please select batch control numbers spreadsheet to upload.");
            return false;
        }

        //var regex = "^(([a-zA-Z]:)|(\\\\{2}\\w+)\\$?)(\\\\(\\w[\\w].*))(.(X|x)(L|l)(S|s))$";
        var regex = "^(([a-zA-Z]:)|(\\\\{2}\\w+)\\$?)(\\\\(\\w[\\w].*))(.(X|x)(L|l)(S|s)(M|m))$";

        if (!(strXLPath.match(regex))) {
            alert(strXLPath + " is not a valid excel file.");
            return false;
        }

        //var strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strXLPath + ";Extended Properties=\"Excel 8.0;HDR=YES\"";
        var strConnString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + strXLPath + ";Extended Properties=\"Excel 12.0;HDR=YES;\";";

        var conn = new ActiveXObject("ADODB.Connection");


        conn.open(strConnString, "", "");

        var rs = new ActiveXObject("ADODB.Recordset");

        var rsrowCount = new ActiveXObject("ADODB.Recordset");

        var schemaRS = new ActiveXObject("ADODB.Recordset");

        var adSchemaTables = 20;

        schemaRS = conn.OpenSchema(adSchemaTables);

        strdatatype = schemaRS.fields(2).value;

        var datatype = "ERISAREQ$";

        if (strdatatype !== datatype) {

            alert(strXLPath + " is not a valid spreadsheet with the numbers: " + strdatatype + "");
            rs = null;
            rsSheet = null;
            conn.close();
            conn = null;
            return false

        }

       rs = conn.execute("select * from ZRangeValid");
        if (rs.fields(0).value != 'YES') {
            alert(strXLPath + " requested numbers spreadsheet is not valid.\nPlease validate the spreadsheet data and retry.")
            rs = null;
            rsSheet = null;
            conn.close();
            conn = null;
            return false

        }

         rsrowCount = conn.execute("SELECT COUNT([Control Number]) from [ERISAREQ$]");

        if (rsrowCount.fields(0).value < 70) 
        {
            var answer = confirm("Uploaded Spreadsheet has less than 70 Numbers, would you like to proceed..?")
            if (answer) 
            {

                rsrowCount = null;
                rsSheet = null;
                conn.close();
                conn = null;
                return true;

            }
            else 
            {
                return false;
            }
        }
        return true
        rs = null;
        rsSheet = null;
        conn.close();
        conn = null;

    }

    function trim(str) {
        return str.replace(/^\s*|\s*$/g, "");
    }

</script>

Solution

  • The issue is solved, when I installed Access Database Engine 2010(32-bit), I was using 64-bit engine, where my ASP.net application is running in 32-bit mode as Visual Studio has 32 bit web server(WebDev.WebServer.exe).