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

Topics: Troubleshooting, Writing modules
Jul 18, 2013 at 5:50 PM
Edited Jul 18, 2013 at 5:52 PM
Hi All!
I'm writing a module in which I need to read data from Excel file. After the first enabling module it worked fine. But then i got error Microsoft.ACE.OLEDB.12.0 provider is not registered on the local machine every time...
Error in logs:
2013-07-18 19:12:28,325 [41] Orchard.Data.Migration.DataMigrationManager - Error while running migration version 0 for Timbioz.Publications.Taxonomies
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
   at System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr, DataSourceWrapper& datasrcWrapper)
   at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
   at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.OleDb.OleDbConnection.Open()
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   at Timbioz.Publications.Taxonomies.Services.TaxonomyStructureService.GetAllTaxonomiesFromExcel()
   at Timbioz.Publications.Taxonomies.Migrations.Create()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Orchard.Data.Migration.DataMigrationManager.Update(String feature)
2013-07-18 19:12:29,765 [49] Orchard.Data.Migration.DataMigrationManager - Error while running migration version 0 for Timbioz.Publications.Taxonomies
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.
   at System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr, DataSourceWrapper& datasrcWrapper)
   at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
   at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
   at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionInternal.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
   at System.Data.OleDb.OleDbConnection.Open()
   at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior)
   at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable)
   at Timbioz.Publications.Taxonomies.Services.TaxonomyStructureService.GetAllTaxonomiesFromExcel()
   at Timbioz.Publications.Taxonomies.Migrations.Create()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Orchard.Data.Migration.DataMigrationManager.Update(String feature)
Migrations.cs where i init my code (after DB creation):
public class Migrations : DataMigrationImpl {

        private readonly ITaxonomyStructureService _taxonomyStructureService;

        public Migrations(ITaxonomyStructureService taxonomyStructureService)
        {
            _taxonomyStructureService = taxonomyStructureService;
        }



        public int Create()
        {
            // Creating table TaxonomyPartRecord
            SchemaBuilder.CreateTable("TaxonomyStructurePartRecord", table => table
                .ContentPartRecord()
                .Column("Type", DbType.String)
                .Column("Section", DbType.String)
                .Column("Theme", DbType.String)
                .Column("Rubric", DbType.String)
                .Column("Tags", DbType.String)
            );


            var terms = _taxonomyStructureService.GetAllTaxonomiesFromExcel();
            _taxonomyStructureService.SeedTypesTerms(terms.Types);
            _taxonomyStructureService.SeedSectionsTerms(terms.Sections);
            _taxonomyStructureService.SeedThemesTerms(terms.Themes);
            _taxonomyStructureService.SeedRubricsTerms(terms.Rubrics);
            _taxonomyStructureService.SeedTagsTerms(terms.Tags);
}}
And Service, where all my logic for Excel read:
public ScicentrTaxonomies GetAllTaxonomiesFromExcel()
        {
            const string fileName = "Temp\\Taxonomy.xlsx";
            var folder = HostingEnvironment.MapPath(@"~/Modules/Timbioz.Publications.Taxonomies");
            var taxonomies = new ScicentrTaxonomies();
            var filePath = Path.GetFullPath(Path.Combine(folder, fileName));
            var existingFile = new FileInfo(filePath);
            var dtExcel = new DataTable { TableName = "MyExcelData" };
            string sourceConstr = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='{0}';Extended Properties= 'Excel 8.0;HDR=Yes;IMEX=1'", existingFile);
            var con = new OleDbConnection(sourceConstr);
            const string query = "Select * from [Лист1$]";
            var data = new OleDbDataAdapter(query, con);
            data.Fill(dtExcel);
            taxonomies.Types = dtExcel.AsEnumerable().Select(x => x[0].ToString()).Where(x => x != "").ToList();
            taxonomies.Sections = dtExcel.AsEnumerable().Select(x => x[1].ToString()).Where(x => x != "").ToList();
            taxonomies.Themes = dtExcel.AsEnumerable().Select(x => x[2].ToString()).Where(x => x != "").ToList();
            taxonomies.Rubrics = dtExcel.AsEnumerable().Select(x => x[3].ToString()).Where(x => x != "").ToList();
            taxonomies.Tags = dtExcel.AsEnumerable().Select(x => x[4].ToString()).Where(x => x != "").ToList();
            return taxonomies;
        }

        public void SeedTypesTerms(List<string> terms) {
            if (_taxonomyService.GetTaxonomyByName("Type") == null) {
                var typeTaxonomy = _contentManager.New<TaxonomyPart>("Taxonomy");
                typeTaxonomy.Name = "Type";
                _orchardServices.ContentManager.Create(typeTaxonomy);
                foreach (var t in terms) {
                    var term = _taxonomyService.NewTerm(typeTaxonomy);
                    term.Name = t;
                    term.Slug = t.ToLatSlug();
                    term.Selectable = true;
                    _taxonomyService.ProcessPath(term);
                    _orchardServices.ContentManager.Create(term);
                }
            }
        }
Please help!!! Thanks in advance!!
Jul 18, 2013 at 9:38 PM
Are you sure it's installed? Another annoying thing is that there's a 32bit and a 64bit version of that and they don't seem to be compatible (as in you have to pick and choose which version to run) so if you're running the website as 64bit you're going to need to install the 64bit version, and the other way around.

Here's a thread about it:
http://social.msdn.microsoft.com/Forums/en-US/1d5c04c7-157f-4955-a14b-41d912d50a64/how-to-fix-error-the-microsoftaceoledb120-provider-is-not-registered-on-the-local-machine

You could also try this:
https://epplus.codeplex.com/

As a way to read/write excel without having to deal with the Microsoft.ACE.OLEDB.12.0 drama.
Jul 19, 2013 at 8:53 PM
EPPlus helped me a lot! Thanks for the help