未在本機電腦上註冊“microsoft.ACE.oledb.12.0”提供者

來源:互聯網
上載者:User

標籤:

錯誤資訊:未在本機電腦上註冊"microsoft.ACE.oledb.12.0"提供者。

解決辦法: http://download.microsoft.com/download/7/0/3/703ffbcb-dc0c-4e19-b0da-1463960fdcdb/AccessDatabaseEngine.exe下載並安裝。

報錯原因:由於使用的是ACCESS2007版本建立的資料庫,但伺服器中沒有相配合使用的程式,所以出錯。

 

錯誤資訊:未在本機電腦上註冊"microsoft.ACE.oledb.12.0"提供者。

解決辦法: 執行當前 Web 請求期間,出現未處理的異常。請檢查堆疊追蹤資訊,以瞭解有關該錯誤以及代碼中導致錯誤的出處的詳細資料。 

錯誤資訊:異常詳細資料: System.InvalidOperationException: 未在本機電腦上註冊"microsoft.ACE.oledb.12.0"提供者。

解決辦法:下載2007 Office system 驅動程式:資料連線組件安裝http://download.microsoft.com/download/7/0/3/703ffbcb-dc0c-4e19-b0da-1463960fdcdb/AccessDatabaseEngine.exe

此下載將安裝一組組件,非 Microsoft Office 應用程式可以使用它們從 2007 Office system 檔案中讀取資料,例如從 Microsoft Office Access 2007(mdb 和 accdb)檔案以及 Microsoft Office Excel 2007(xls、xlsx 和 xlsb)檔案中讀取資料。這些組件還支援與 Microsoft Windows SharePoint Services 和文字檔建立串連。此外,還會安裝 ODBC 和 OLEDB 驅動程式,供應用程式開發人員在開發與 Office 檔案格式連線應用程式程式時使用。

 

如果您是使用 OLEDB 的應用程式開發人員,請將 ConnectionString 屬性的 Provider 參數設定為"Microsoft.ACE.OLEDB.12.0"。如果要串連到 Microsoft Office Excel 資料,請將"Excel 12.0"添加到 OLEDB 連接字串的擴充屬性中。

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

 

如果您是使用 ODBC 串連到 Microsoft Office Excel 資料的應用程式開發人員,請將連接字串設定為"Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=path to xls/xlsx/xlsm/xlsb file"詳情:http://www.microsoft.com/downloads/zh-cn/details.aspx?displaylang=zh-cn&FamilyID=7554f536-8c28-4598-9b72-ef94e038c891

 

或者:解決辦法1 (驗證可以了)

  選擇 該應用程式的 應用程式集區 ------>選擇進階設定 --------->啟用32位應用程式 ------->true

解決辦法2

  Microsoft.ACE.OLEDB.12.0是不能再x64上使用的,你要強制把你的web application編譯成x86再發布到Win08 x64上,記得在Application pool上設定Enable 32bit Application = true。(沒有驗證)

作業碼:

 

        private void openToolStripMenuItem_Click(object sender, EventArgs e)        {            OpenFileDialog openDialg= new OpenFileDialog();            //openDialg.ShowDialog();            openDialg.InitialDirectory="C:\\Users\\Administrator\\Desktop";            openDialg.Filter="Excel Files(2003-2007)|*.xls|Excel File(*.xlsx)|*.xlsx|All files (*.*)|*.*";            openDialg.Title="開啟Excel檔案";            openDialg.FilterIndex=0;            openDialg.RestoreDirectory=true;                        OleDbDataAdapter da;            DataSet ds=new DataSet();            if(openDialg.ShowDialog()==DialogResult.OK)            {                if (string.IsNullOrEmpty(openDialg.FileName))                {                    MessageBox.Show("請選擇Excel檔案!");                    DT=null;                }                else                {                    try{                        string FileName=openDialg.FileName.Substring(openDialg.FileName.LastIndexOf(‘.‘));                        string connStr="";                        switch(FileName)                        {                            case ".xls":                                {                                    connStr = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" + openDialg.FileName + "; Extended Properties=‘Excel 8.0;HDR=Yes;IMEX=1‘";                                    break;                                }                            case ".xlsx":                                {                                    connStr = "Provider=Microsoft.Ace.OLEDB.12.0;data source=" + openDialg.FileName + ";Extended Properties=‘Excel 12.0;HDR=Yes;IMEX=1;‘";                                    break;                                }                            default:                                {                                    connStr = "Provider=Microsoft.Jet.OLEDB.4.0;data source=" + openDialg.FileName + "; Extended Properties=‘Excel 8.0;HDR=Yes;IMEX=1‘";                                    break;                                }                        }                        //Excel資料讀入之後將他儲存到DataTable中                        string sql="select * from["+GetExcelFirstTableName(openDialg.FileName,connStr)[0].ToString().Trim()+"]";                        OleDbConnection con=new OleDbConnection(connStr);                        con.Open();                        da=new OleDbDataAdapter(sql,con);                        da.Fill(ds);                        if(ds.Tables[0].Rows.Count==0)                        {                            //開啟的檔案內容為空白,則繼續保持DataTable為空白                            MessageBox.Show("選擇的檔案中沒有資料");                            DT=null;                        }                        else                        {                            // 開啟檔案不為空白                            DT=ds.Tables[0];                            //在DataGridviewe中顯示DT                            this.dataGridView_Excel.DataSource=DT;                        }                        //return DT;                    }                    catch(Exception exp)                    {                        MessageBox.Show(exp.Message.ToString());                        //return DT;                        //this.dataGridView_Excel.DataSource=DT;                        //this.dataGridView_Excel.Rows.Add(DT.Rows[0].)                        //while(this.dataGridView_Excel.Rows)                    }                //StreamReader sr=File.OpenText(openDialg.FileName);                //while(sr.EndOfStream!=true)                //{                //    FileStream filestream = new FileStream();                //    IFileReaderService                 //}            }        }    }

 

/// <summary>        /// 擷取第一個Sheet的名稱        /// </summary>        /// <param name="excelFileName">Excel檔案名稱</param>        /// <param name="strExtension">讀取Excel檔案資料的資料連線</param>        /// <returns></returns>        private static ArrayList GetExcelFirstTableName(string excelFileName, string strExtension)        {            ArrayList tablenameList = new ArrayList();            try            {                if (File.Exists(excelFileName))                {                    using (OleDbConnection conn = new System.Data.OleDb.OleDbConnection(strExtension))                    {                        conn.Open();                        DataTable DT = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);                        tablenameList.Add(DT.Rows[0][2].ToString().Trim());                        return tablenameList;                    }                }            }            catch (Exception exp)            {                MessageBox.Show(exp.Message.ToString());            }            return tablenameList;        }

 

未在本機電腦上註冊“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.