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

时间:2017-10-26 06:25:32

标签: c# oledb adodb

我正在尝试使用

从Excel 2016文件中读取

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

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

  

无法找到提供商。它可能没有正确安装

错误。我在.Net 3.5,Access数据库引擎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>

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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