3

I am trying to develop a kind of Windows form application using Visual Studio 2013.

In my project I have such a code like this :

public class AccessFile
{
    string strconnection = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=AccessTemp.mdb";
    private void InsertSellItems(List<TTMSModel> lstttms )
    {
        try
        {
            foreach (TTMSModel t in lstttms)
            {
                if (t.TypeMember == "حقیقی") t.TypeMember = "1";
                else
                {
                    t.TypeMember = "2";
                }
                OleDbConnection objconnection = new OleDbConnection(strconnection);
                OleDbCommand objcommand = new OleDbCommand("INSERT INTO Foroush_Detail" +
                                                           "(KalaKhadamatName,KalaCode,BargashtType,Price,MaliatArzeshAfzoodeh,AvarezArzeshAfzoodeh,HCKharidarTypeCode,KharidarPostCode,KharidarPerCityCode,KharidarTell,KharidarAddress,KharidarName,KharidarLastNameSherkatName,KharidarEconomicNO,KharidarNationalCode,HCKharidarType1Code,CityCode,stateCode,IsSent,Sarjam)" +
                                                           "VALUES('فروش'," +"'0'"+",'0','"+t.PriceAmount+"','"+t.MayorAmount+"','"+t.TaxAmount+"','"+t.TypeMember+"','"+t.ZipCode+"','"+t.City+"','"+t.PhoneNumber+"','"+t.Address+"','"+t.Name+"','"+t.Name+"','"+t.EconomicNumber+"','"+t.IntNumber+"','2','"+t.City+"','"+t.Province+"','0','0')",
                                                           objconnection);
                objconnection.Open();
                objcommand.ExecuteNonQuery();
                objconnection.Close();
            }
        }
        catch (OleDbException a)
        {
        }
    }

So everything works fine. My operating system is Windows 7 64-bit. So when I try to run this code I get this error:

the microsoft.jet.OLEDB4 provider is not registered on the local machine

I will be appreciated if give me some help?

Romil Kumar Jain
  • 20,239
  • 9
  • 63
  • 92
Ehsan Akbar
  • 6,977
  • 19
  • 96
  • 180

4 Answers4

4

Use Accdb instead of mdb and install 64 bit drivers from this location.

Connection string will be :

"Provider=Microsoft.ACE.OLEDB.12.0; Data Source= yourdbname ;Jet OLEDB:Database Password=yourpassword;"

You need to install 64 bit drivers on 64 bit OS and 32 bit drivers on 32 bit OS.

Download Access drivers

Romil Kumar Jain
  • 20,239
  • 9
  • 63
  • 92
4

If your Microsoft Access version is 2003 please upgrade it to a newer version and read below article -I add the summary of that below-.

Data Programming with Microsoft Access 2010

Summary: Learn how to develop either native (C, C++, Java, VBA) or managed (C#, Visual Basic.NET) data access code with Microsoft Office Access 2007 or Microsoft Access 2010. Learn about the Access architecture, the ACE engine and data providers, 32-bit and 64-bit platforms, and what things to consider when you choose an optimal data access technology for your new or legacy database project.

Applies to: Access 2007 | Access 2010 | Office 2010


Prior to Access 2007, Access used the Microsoft Joint Engine Technology (JET) engine. Even though JET was generally seen as part of Access, the JET engine used to be a separate product. Since Microsoft Windows 2000 release, JET was included as part of the Windows operating system and then distributed or updated with the Microsoft Data Access Components (MDAC). However, with Access 2007 release the JET engine was deprecated and is no longer distributed with MDAC. Instead, Access now uses an integrated and improved ACE engine whose development started by taking a code snapshot of the original JET code base.


The important related part is:

The ACE providers (ACE DAO, ACE OLE DB or ACE ODBC) for Access 2007 product are available only in 32-bit. The ACE providers for Access 2010 product are available in both 32-bit and 64-bit editions.

That aware you need an ACE provider for Access 2010.

For using that you need a new connection string like for Access 2010:

Standard security

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb;
Persist Security Info=False;

With database password

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccessFile.accdb;
Jet OLEDB:Database Password=MyDbPassword;

Download it from Microsoft Access Database Engine 2010 Redistributable.

Community
  • 1
  • 1
shA.t
  • 16,580
  • 5
  • 54
  • 111
2

Your whole project will have to be set to be compiled for the x86 platform. The needed assemblies for Microsoft Jet databases (Microsoft.Jet.OLEDB provider) are available for 32-bit only. There simply is (and, according to Microsoft, there never will be) no 64 bit version. This is why your application is not able to find the Microsoft.Jet.OLEDB, when compiled for x64. Your only option to get this working, is to switch your application (and all dependent assemblies) to 32-bit (x86 platform).

shA.t
  • 16,580
  • 5
  • 54
  • 111
Peter Brennan
  • 1,366
  • 12
  • 28
0

Just "Enable 32-bit Applications" setting to True, in the Advanced Settings for the Application Pool.

1.-Open IIS 2.-Change the appPool on Advanced Settings 3.-true to enable to 32-bit application.

BSG
  • 2,084
  • 14
  • 19
  • how can i find Advanced Settings for the Application Pool.? – Ehsan Akbar May 05 '15 at 11:31
  • I don't have any installed iis in my local machine ,my project is windows form not webform!!!! – Ehsan Akbar May 05 '15 at 11:36
  • Else try this Project---> Properties--->Build--->Target Framework---> X64 – BSG May 05 '15 at 11:42
  • Goto Menu Tools, Options, select Projects And Solutions, check the show advanced build configurations. Now in the Build Menu you will be able to go to the Cofig Manager and set output to x86. – BSG May 05 '15 at 11:50
  • my project has multi solution like repository ,domainclass and ... all of my projects should be changed to x64 – Ehsan Akbar May 05 '15 at 12:07
  • Do that for project where you are getting the error. – BSG May 05 '15 at 12:24
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/76991/discussion-between-bsg-and-ehsan-akbar). – BSG May 05 '15 at 13:17