When asp.net imports Excel Data Using OLEDB, the system prompts: "Microsoft. Jet. OLEDB.4.0" is not registered on the local computer"

Source: Internet
Author: User

In my project, I made a module for importing data from an Excel table. In general, the import of Excel in the asp.net project is divided into three categories:

1) Use the c # built-in solution System. Data. OleDb (limited and common)

2) use the Excel COM component (with version issues)

3) Use a pseudo Excel file or text stream to customize the data format as needed. At the same time, perform reverse formatting on the server.

I use solution 1. The associated development environment is as follows:

Windows 7 (x64)

Visual Studio 2010

Code Used in the solution:

public sealed class ExcelHelper
{ private const string CONNECTION_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0;"; public static DataSet ExcelDataSource(string filePath, string sheetName) { OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + sheetName + "$]", string.Format(CONNECTION_STRING,filePath)); DataSet ds = new DataSet(); oada.Fill(ds); return ds; } public static List<string> ExcelSheetName(string filePath) { List<string> list = new List<string>(); OleDbConnection conn = new OleDbConnection(string.Format(CONNECTION_STRING, filePath)); conn.Open(); DataTable sheetNames = conn.GetOleDbSchemaTable (System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); conn.Close(); foreach (DataRow dr in sheetNames.Rows) { list.Add((string)dr[2]); } return list;}

During execution, the program throws:

Exception details: System. InvalidOperationException: the Microsoft. Jet. OLEDB.4.0 provider is not registered on the local computer.

Cause analysis:

Microsoft ole db Provider for Jet for Access and Excel databases are not available in 64-bit versions.

Final Solution:

In IIS, enable the 32-bit program and set it as shown in the figure.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.