找不到提供商。它可能没有正确安装。连接 excel 2016

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

我正在尝试使用

从 Excel 2016 文件中读取

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

我正在使用 ActivexObject 和 ADODB.Connection 打开与 excel 文件的连接。我得到

Provider cannot be found. It may not be properly installed

错误。我在 .Net 3.5、Access Database Engine 2010(64 位)和 Office 2016(64 位)和 windows 7(64 位)和 Visual Studio 2008 中使用 c#。请帮助我。我搜索了很多但找不到任何解决方案。我附上了我的代码和错误图片。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>

如果您使用的是Visual studio,您可以使用服务器资源管理器,通过选择oledb 提供程序连接访问db 文件,然后在属性 window 中您可以获得连接字符串。

问题已解决,当我安装 Access Database Engine 2010(32 位)时,我使用的是 64 位引擎,而我的 ASP.net 应用程序是 运行 在 32 位模式下因为 Visual Studio 有 32 位网络服务器 (WebDev.WebServer.exe).