[.Net] unregistered "microsoft.ACE.oledb.12.0" on the local computer solutions provider directory

text

#wrong description:

  In .net development project, read the excel file information microsoft.ACE.oledb, given:

  "Is not registered on the local computer" microsoft.ACE.oledb.12.0 "Provider"

# Code sample:

Copy the code
 1      static void Main(string[] args)
 2         {
 3             readexcel("D:\\test\\xlsxtest.xlsx");
 4         }
 5         public static void readexcel(string _path)
 6         {
 7             DataTable dt = new DataTable();
 8             string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + _path + ";" + "Extended Properties=\"Excel 12.0;HDR=No\"";
 9 
10             using (OleDbConnection connection = new OleDbConnection(connectionString))
11             {
12                 string SQL = "select * from [sheet1$]";
13                 try
14                 {
15                     OleDbCommand comm = new OleDbCommand(SQL, connection);
16                     if (connection.State != ConnectionState.Open)
17                         connection.Open();
18                     OleDbDataAdapter Adpter = new OleDbDataAdapter(comm);
19                     Adpter.Fill(dt);
20                 }
21                 catch (Exception ex)
22                 {
23                     dt = null;
24                 }
25                 finally
26                 {
27                     if (connection.State == ConnectionState.Open)
28                         connection.Close();
29                 }
30 
31                 foreach (DataRow item in dt.Rows)
32                 {
33                     string sds = item[0].ToString();
34                     Console.WriteLine(item[0].ToString() + "//" + item[1].ToString() + "//" + item[2].ToString());
35                     if (item[1].ToString() == string.Empty)
36                     {
37                         break;
38                     }
39                 }
40                 Console.ReadKey();
41             }
42         }
Copy the code

 

# Error reasons:

  The main reasons are the following:

  1, no data access component installation, need to install the version of data access components ( AccessDatabaseEngine );

  2, do not install the appropriate version of Office client, we need to install the appropriate version of Office client;

  3, no default IIS application pool properties required to enable 32-bit applications in appropriate IIS application pool;

  4, the connection string problems. Using Microsoft.Jet.OleDb.4.0, can read previous versions excel2007, office does not need to be deployed on the client machine, using Microsoft.Ace.OleDb.12.0 time, you need to install the engine.

  5, by the way, using the "Microsoft.Jet.OLEDB.4.0", also reported similar errors, it is possible because, Microsoft.Jet.OLEDB.4.0 not supported on 64-bit systems, we need to modify the architecture from x64 to x86, or whether the ASP.NET WinForm; Microsoft.ACE.OLEDB.12.0 or modify the connection string and the data access component mounted AccessDatabaseEngine x64;

#solution:

  1, the mounting data access components:

  1) applies to the office2007

  Microsoft Access Database Engine 2007 Office system Driver: Data Connectivity Components
  https://www.microsoft.com/zh-cn/download/details.aspx?id=23734     (this link has expired, the direct use of Microsoft Access Database Engine 2010 Redistributable just fine )

  2) apply to the office2010

  Microsoft Access Database Engine 2010 Redistributable
 
  This download will install a set of components, the non-Microsoft Office applications they can be used to read data from the 2007/2010 Office system file, for example, from Microsoft Office Access 2007/2010 (mdb and ACCDB) files, and Microsoft Office Excel 2007/2010 ( xls, xlsx and xlsb) read data file. The component also supports establishing a connection with Microsoft Windows SharePoint Services and text files.
  Additionally, you install the ODBC and OLEDB drivers, supplies used during application development with Office file formats connected with the program developers.

  2, the IIS application pool, set the "" Enable compatible 32 -bit applications ", this setting applies to web projects;

  Figure:

  
 
 
note:
Download When Microsoft Access Database Engine 2010 Redistributable will choose to download the x86 or x64, as:
 
The premise is to look at the server is x64 or x86, and x64-server can be installed in two versions;

  If you download and install the x64, then you should choose anycpu desktop applications or x64 release, and web projects are not compatible, no matter how you posted;

  If you download and install an x86, then you should choose x86 desktop publishing program, and web publishing projects like normal;

* Summary: If you are a web project, you can download the x86, publishing election anycpu just fine, and then set the application pool like a 32-bit compatible;

* Finally, say, with this, you do not need to install office software;

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 

  3, the connection string

  Notably the following two situations:

  1) Use Office 2007 OLEDB driver (ACE 12.0) connected to the older 97-2003 Excel workbook.

  Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\\myFolder\\myOldExcelFile.xls;
  Extended Properties="Excel 8.0;HDR=YES";
     "HDR = Yes;" indicates the first row contains the column name, rather than data. "HDR = No;" contrary;

  2) read xlsx format excel

  Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\\myFolder\\myExcel2007file.xlsx;
  Extended Properties="Excel 12.0 Xml;HDR=YES";
    "HDR = Yes;" indicates the first row contains the column name, rather than data. "HDR = No;" contrary;
 
  Microsoft.ACE.OLEDB connection string reference address: https://www.connectionstrings.com/ace-oledb-12-0/
 

Guess you like

Origin www.cnblogs.com/pangguoming/p/11310138.html