【问题标题】:Diagnosing an OLEDB exception when Quering Excel 2010查询 Excel 2010 时诊断 OLEDB 异常
【发布时间】:2010-11-30 11:16:18
【问题描述】:

通过 SQL 查询 excel 表,我曾经使用过:

Dim excelConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strPath + ";Extended Properties=""Excel 8.0;IMEX=1;HDR=YES;"""

Dim excelConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + strPath + ";Extended Properties=""Excel 12.0;IMEX=1;HDR=YES;"""

在我安装 Office 2010 之前,这一切正常。

现在我得到了一个

Microsoft.Ace.OLEDB.12.0 提供程序未在此计算机上注册 例外。

如何找到正确的连接字符串/提供程序?

【问题讨论】:

    标签: sql vb.net excel ms-office excel-2010


    【解决方案1】:

    我相信 Excel 2010 是这样的:

    Dim excelConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=D:\\MyDocs\\oledb.xlsx;Mode=Share Deny Write;Extended Properties=""HDR=YES;"";Jet OLEDB:Engine Type=37"
    

    这似乎在我的 Visual Studio 中工作,我让 Excel 生成查询字符串,其中包含额外的条目。

    【讨论】:

    • 我今天也遇到了同样的情况,你的回答很有帮助
    • 希望我能对此投票 10 次。刚刚在这个问题上花了几个小时,你的答案解决了它。谢谢。
    【解决方案2】:

    我按照上面的建议下载并安装了 Office System Driver: Data Connectivity Components - 以下代码有效:

        string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Password=\"\";User ID=Admin;Data Source=d:\\Sample.xlsx;Mode=Share Deny Write;Extended Properties=\"HDR=YES;\";Jet OLEDB:Engine Type=37";
    
        OleDbConnection connection = new OleDbConnection(connectionString);
    
        try
        {
            connection.Open();
    
            OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", connection);
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            adapter.SelectCommand = command;
    
            DataSet ds = new DataSet();
            adapter.Fill(ds);
    
            GridView1.DataSource = ds;
            GridView1.DataBind();
    
        }
        catch (Exception)
        {            
            //throw;
        }
        finally
        {
            connection.Close();
        }
    

    【讨论】:

    • 我怎么没有得到任何结果。但它并没有给我任何异常。
    【解决方案3】:

    也许您卸载了 Access 数据库引擎 (ACE) 组件?它们仍可从 MSDN 以2007 Office System Driver: Data Connectivity Components 下载。

    【讨论】:

      猜你喜欢
      • 2013-05-26
      • 1970-01-01
      • 2019-02-21
      • 1970-01-01
      • 2015-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多