The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine

Sushil Agarwal 381 Reputation points
2022-07-25T18:21:25.197+00:00

I am having Windows 64 Bit os build 19043.1826 21H1, i have office 21 64 bit on this pc, but when i want to open an xls file i am getting the above error,
if i build application 32bit it open file correctly, but if i make it 64 bit i can not install Microsoft.Jet.OLEDB.4.0 .

how to handle this situation, is making app 32 bit is the only solution ?, what i loose making it 32 bit ? my pc has got 16gb ram

       switch (filextntn)  
                    {  
                        case ".XLS":  
                            //https://qawithexperts.com/article/c-sharp/read-excel-file-in-c-console-application-example-using-oledb/168  
                            strExcelCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ofn.FileName +  
                                    ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";  
                            break;  
                        case ".XLSX":  
                            strExcelCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ofn.FileName + ";Extended Properties=\"Excel 12.0 Xml;HDR=YES\"";  
                            break;  
                        case ".XLSB":  
                            strExcelCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ofn.FileName + ";Extended Properties=\"Excel 12.0;HDR=YES\"";  
                            break;  
                        case ".XLSM":  
                            strExcelCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ofn.FileName + ";Extended Properties=\"Excel 12.0 Macro;HDR=YES\"";  
                            break;  
                        case ".TXT":  
                            //EDITL.txt for BAJAJ  
                            ProcessTxtFile(ofn.FileName);  
                            return;  
                        default:  
                            strExcelCon = " File Type:" + filextntn;  
                            break;  
                    }  

if i change the connectiong string to "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ofn.FileName + ";Extended Properties=\"Excel 12.0;HDR=YES\""; to open an xls file it is also giving error and reading it correctly.

how to solve this issue

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,863 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jack J Jun 24,476 Reputation points Microsoft Vendor
    2022-07-26T02:36:45.4+00:00

    @Sushil Agarwal , Welcome to Microsoft Q&A, based on my test, I reproduced your problem.

    According to my research, Please try the following steps to access excel file without the exception.

    First, Please install the software Microsoft Access Database Engine 2010 Redistributable.

    Second, you could try the following connection string to open a xls file.

    "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path+ ";Extended Properties='Excel 12.0;HDR=NO;IMEX=1;'";  
    

    Finally, you could use the above connection string to access the excel file.

    Note: Based on my further test, the above code works both in 32 bit app or 64 bit app.

    Hope the above steps could help you.

    Best Regards,
    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    2 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. vinod gaikwad 0 Reputation points
    2024-05-22T06:54:05.9833333+00:00

    User's image

    0 comments No comments