诊断的OLEDB异常时Quering Excel 2010中(Diagnosing an OLEDB

2019-07-19 00:32发布

要查询经由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供应商未注册在本机的异常。

我怎样才能找出正确的连接字符串/供应商?

Answer 1:

也许你卸载Jet数据库引擎(ACE)组件? 他们仍然可以从MSDN下载的2007 Office系统驱动程序:数据连接组件 。



Answer 2:

我相信,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"

这会出现在我的视觉工作室的工作,我得到了Excel中生成的查询字符串,它有它的额外名额。



Answer 3:

我下载并安装Office系统驱动程序:数据连接组件如上建议 - 与下面的代码工作:

    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();
    }


文章来源: Diagnosing an OLEDB exception when Quering Excel 2010