C # accesses Excel error message through OLE DB: Microsoft is not registered on the local computer. ace.oledb.12.0 "provider. The online query learns that you need to download the Microsoft Access 2010 Database Engine Redistributable package to install. As: https://www.microsoft.com/zh-CN/download/details.aspx?id=13255.
Supported operating Systems
Windows 7, Windows 8, Windows Server 2003, Windows Server 2003 Service Pack 1, Windows Server 2003 Service Pack 2, Windows Server R2, Windows Server Service Pack 2, Windows Vista Service Pack 1, Windows XP Service Pack 2
only 32-bit Access database engine can be used on Windows XP Service Pack 3
Usage scenarios:
- If you are using OLE DB application, set the Provider parameter of the ConnectionString property to "microsoft.ace.oledb.12.0".
If you connect to Microsoft Office Excel data, add the appropriate OLE DB connection string extension properties based on the Excel file type:
File type (extension) & nbsp Extended Properties
------------------------------------------------------------------------------ ---------------
Excel 97-2003 workbook (. xls) & nbsp "Excel 8.0"
Excel 2007-2010 Workbook (. xlsx) "Excel 12.0 Xml"
Enable macro Exce L 2007-2010 Workbook (. xlsm) Excel 12.0 macros
Excel 2007-2010 non-XML binary workbook (. xlsb) "Exce L 12.0 "
- If you are an application developer who uses ODBC to connect to Microsoft Office Access data, set the connection string to "Driver={microsoft Access Driver (*.mdb, *.accdb)};D bq= Path to mdb/accdb file "
- If you are an application developer who uses ODBC to connect to Microsoft Office Excel data, set the connection string to "Driver={microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xls b)};D bq=path to xls/xlsx/xlsm/xlsb file "
A test example:
1 Public StaticDataTable GetData (stringfileName)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 stringConnStr =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 =NewOleDbConnection (connstr))7 {8 9 TryTen { One Conn. Open (); ADataTable DT = conn. GetOleDbSchemaTable (OleDbSchemaGuid.Tables,NULL); - vartableName = dt. rows[0][2]. ToString (). Trim (); - stringCmdtxt =string. Format ("SELECT * from [{0}]", tableName); the - //trace.write ("Enquiry form:" + cmdtxt); -OleDbDataAdapter da =NewOleDbDataAdapter (Cmdtxt, conn); -DataSet ds =NewDataSet (); + da. Fill (DS); - returnDs. tables[0]; + } A Catch(Exception e) at { - - //trace.writeline ("GetData error:" + e.message); - return NULL; - } - finally in { - Conn. Close (); to } + } -}
Error: "Not registered on the local computer" Microsoft. ace.oledb.12.0 "