錯誤:“未在本機電腦上註冊“microsoft.ACE.oledb.12.0”

來源:互聯網
上載者:User

標籤:

   C#通過OleDb訪問Excel 錯誤資訊:未在本機電腦上註冊“microsoft.ACE.oledb.12.0”提供者。網上查詢得知需要下載安裝Microsoft Access 2010 資料庫引擎可再發行程式包。為:https://www.microsoft.com/zh-CN/download/details.aspx?id=13255。

   

支援的作業系統

Windows 7, Windows 8, Windows Server 2003, Windows Server 2003 Service Pack 1, Windows Server 2003 Service Pack 2, Windows Server 2008 R2, Windows Server 2008 Service Pack 2, Windows Vista Service Pack 1, Windows XP Service Pack 2

      只有 32 位 Access 資料庫引擎可在 Windows XP Service Pack 3 上使用

使用情境:

  1. 如果使用 OLEDB 的應用程式,將 ConnectionString 屬性的 Provider 參數設定為“Microsoft.ACE.OLEDB.12.0”。 

    如果串連到 Microsoft Office Excel 資料,根據 Excel 檔案類型添加相應的 OLEDB 連接字串擴充屬性: 

    檔案類型(副檔名)                                             擴充屬性
    ---------------------------------------------------------------------------------------------
    Excel 97-2003 活頁簿 (.xls)                                  “Excel 8.0”
    Excel 2007-2010 活頁簿 (.xlsx)                             “Excel 12.0 Xml”
    啟用巨集 Excel 2007-2010 活頁簿 (.xlsm)     “Excel 12.0 宏”
    Excel 2007-2010 非 XML 二進位活頁簿 (.xlsb)     “Excel 12.0”

  2. 如果您是使用 ODBC 串連到 Microsoft Office Access 資料的應用程式開發人員,請將連接字串設定為“Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=path to mdb/accdb file”
  3. 如果您是使用 ODBC 串連到 Microsoft Office Excel 資料的應用程式開發人員,請將連接字串設定為“Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=path to xls/xlsx/xlsm/xlsb file”

一個測例子:

 1  public static DataTable GetData(string fileName) 2         { 3             if (!File.Exists(fileName)) return null; 4             //string connStr = string.Format(@"Provider=MMicrosoft.ACE.OLEDB.12.0;data source=‘{0}‘;Extended Properties=‘Excel 8.0;HDR=YES;IMEX=1‘;", fileName); 5             string connStr = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;data source=‘{0}‘;Extended Properties=‘Excel 12.0;HDR=YES;IMEX=1‘;", fileName); 6             using (OleDbConnection conn = new OleDbConnection(connStr)) 7             { 8  9                 try10                 {11                     conn.Open();12                     DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);13                     var tableName = dt.Rows[0][2].ToString().Trim();14                     string cmdTxt = string.Format("select * from [{0}]", tableName);15                 16                 //    Trace.Write("查詢表:" + cmdTxt);17                     OleDbDataAdapter da = new OleDbDataAdapter(cmdTxt, conn);18                     DataSet ds = new DataSet();19                     da.Fill(ds);20                     return ds.Tables[0];21                 }22                 catch (Exception e)23                 {24 25                   //  Trace.WriteLine("GetData錯誤: " + e.Message);26                     return null;27                 }28                 finally29                 {30                     conn.Close();31                 }32             }33         }

 

錯誤:“未在本機電腦上註冊“microsoft.ACE.oledb.12.0”

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.