2015-05-05 38 views
2

我試圖使用Visual Studio 2013年的microsoft.jet.OLEDB4​​供應商未註冊的本地機器

在我的項目開發一種Windows窗體應用程序中我有這樣的代碼,這樣的:

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) 
     { 
     } 
    } 

所以一切工作正常。我的操作系統是Windows 7 64位。所以,當我嘗試運行此代碼時,出現此錯誤:

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

如果給我一些幫助,我將不勝感激?

+0

重複:http://stackoverflow.com/q/1991643/1070452 – Plutonix

回答

3

如果您的Microsoft Access版本是2003,請升級到較新的版本和下面的文章閱讀-I添加如下─摘要。

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 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.

知道您需要Access 2010的ACE提供程序。

對於使用你需要一個新的connection string像訪問2010:

標準安全

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

隨着數據庫密碼

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

Microsoft Access Database Engine 2010 Redistributable下載。

0

只需在應用程序池的高級設置中將「啓用32位應用程序」設置爲True即可。

1.開IIS 2. - 更改APPPOOL上高級設置 3.真,以使32位應用程序。

+0

我怎麼找到應用程序池的高級設置。 –

+0

我沒有在我的本地機器上安裝iis,我的項目是windows窗體不是webform !!!! –

+0

否則嘗試此項目--->屬性--->構建--->目標框架---> X64 – BSG

2

您必須將整個項目設置爲針對x86平臺進行編譯。 Microsoft Jet數據庫所需的程序集(Microsoft.Jet.OLEDB提供程序)僅適用於32位只有。簡而言之(並且據微軟稱,從來沒有)沒有64位版本。這就是爲什麼當爲x64編譯時,應用程序無法找到Microsoft.Jet.OLEDB的原因。你唯一的選擇是讓你的應用程序(和所有相關的程序集)切換到32位(x86平臺)。

3

使用Accdb而不是mdb並從此位置安裝64位驅動程序。

連接字符串將是:

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

你需要安裝在64位操作系統的64位驅動程序和32位操作系統的32個驅動程序。

Download Access drivers

相關問題