34

every thing work fine locally but this error occurs when I publish it:

 The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

and stack trace

[InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.]
System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr, DataSourceWrapper& datasrcWrapper) +1027372
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +337
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +86
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +31
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +76
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
System.Data.OleDb.OleDbConnection.Open() +43
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +123
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +319
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1618
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +97
System.Web.UI.WebControls.ListControl.PerformSelect() +34
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +74
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +66
System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +29
System.Web.UI.Control.PreRenderRecursiveInternal() +103
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Control.PreRenderRecursiveInternal() +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2496

I am using MS access 2007 database and this my connection string within web.config

        <add name="ConnectionString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\OmanLegalDB.accdb;Persist Security Info=True" providerName="System.Data.OleDb"/>

any suggestions for this problem

Kyabroudi
  • 549
  • 1
  • 7
  • 22

4 Answers4

44

For version 12.0 you need to install MDAC 2010 from here.

This has to be done on the server where you publish your application. You need to install the x86 version if the target machine is 32 bit or the x64 version if the target machine is 64 bit and your application is built with configuration Any CPU.

Marcel N.
  • 13,726
  • 5
  • 47
  • 72
  • I think MDAC should be installed cuz there is another access db already published on the server – Kyabroudi Jun 24 '12 at 18:19
  • @KhaledYabroudi: Yes, but it must be an older version. If it's indeed 2010, then review if the machine is x64 and your build is 'x86'. In that case you need the MDAC x86 version, not x64. – Marcel N. Jun 24 '12 at 18:21
  • @KhaledYabroudi: As far as I know, it is possible to install both versions side-by-side. So that's probably the safest way, in order to keep compatibility for existing apps deployed there. – Marcel N. Jun 24 '12 at 18:35
  • I'll try to connect with server admin. ASAP to check this !! – Kyabroudi Jun 24 '12 at 18:40
  • This is still the case for Access 2013. I created a udl file which uses Microsoft.ACE.OLEDB.15.0 and works fine after installing. – Andez Nov 24 '13 at 18:10
  • Is there anything more lightweight than MDAC for reading MS Access? I have to read an access db as part of an install and I don't want to have to install MDAC on the client just for that. Also, it is kind of a pain dealing with the 32bit versus 64bit versions and getting the right version of MDAC installed and recognized. For example, there is a lightweight Excel API here: https://github.com/ExcelDataReader/ExcelDataReader – Dan Csharpster Dec 15 '14 at 21:56
  • 1
    @DanCsharpster: None that I know of. Indeed, setting this up at install time can be a pain. I assume it is not possible to switch from Access to something else, like SQlite, that can be handled with less effort. – Marcel N. Dec 16 '14 at 05:40
  • @MarcelN., it was originally in Excel and we had been using that library I mentioned, but someone added a column and a table and refused to put it in anything but MS Access, so we had to switch to reading it from there. We've just vetoed his approach and have switched back to Excel for now. – Dan Csharpster Dec 16 '14 at 18:42
  • The tip about x86 vs x64 was helpful to me - I was running this in LINQPad5 (AnyCPU version) and the problem went away when I used LINQPad5 (x86 version). Thanks! – Colin Jul 25 '16 at 19:30
  • I have MS Office 64-bit, I installed the x64 version of MDAC, and have the build in Visual Studio 2017 set to "Debug" and "x64", but it still comes up with this error. – Aaron Franke Apr 23 '19 at 22:38
11

As suggested in here You need to change the Solution Platform from "Any CPU" to "x86".

Mohsen Afshin
  • 13,273
  • 10
  • 65
  • 90
3

Your connection string is right so this error could be caused by following reason:

  • If your Office is 32 bit on a 64bit machine and MDAC driver installed is 64bit. In this case you would need to install 32bit MDAC driver to match 32bit Office binaries.

This post has detailed info on how to troubleshoot it.

AvkashChauhan
  • 20,495
  • 3
  • 34
  • 65
0

If you don't want to download anymore add on's another fix I've found is changing ACE to JET and 12 to 4.

'Microsoft.JET.OLEDB.4.0'

You then also need to make sure that you change the database from .accdb to .mdb format and that should work.