My question follows this one: Writing large number of records (bulk insert) to Access in .NET/C#
I've tried the method indicated with DAO. At first, it did not work, getting this error: Retrieving the COM class factory for component with CLSID {681EF637-F129-4AE9-94BB-618937E3F6B6} failed due to the following error: 80040154.) I've searched and found a solution with registry keys, it worked, but when I've tried on an other PC, the founction makes my application crach.
There is my code and where it fails:
using Microsoft.Office.Interop.Access.Dao;
public void ExportDataTableToAccess(System.Data.DataTable dtOutData)
{
    Microsoft.Office.Interop.Access.Application access = new Microsoft.Office.Interop.Access.Application();
    _DBEngine dbEngine = null;
    try
    {
        dbEngine = access.DBEngine; //Fails here
        //I have tried   DBEngine dbEngine = access.DBEngine
        //did not work either
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    try
    {
        Boolean CheckFl = false;
        string DBPath = dbPath;
        Database db = dbEngine.OpenDatabase(dbPath);
        Recordset AccesssRecordset = db.OpenRecordset(dtOutData.TableName);
        Field[] AccesssFields = new Field[dtOutData.Columns.Count];
        //Loop on each row of dtOutData
        for (Int32 rowCounter = 0; rowCounter < dtOutData.Rows.Count; rowCounter++)
        {
            AccesssRecordset.AddNew();
            //Loop on column
            for (Int32 colCounter = 0; colCounter < dtOutData.Columns.Count; colCounter++)
            {
                // for the first time... setup the field name.
                if (!CheckFl)
                    AccesssFields[colCounter] = AccesssRecordset.Fields[dtOutData.Columns[colCounter].ColumnName];
                AccesssFields[colCounter].Value = dtOutData.Rows[rowCounter][colCounter];
            }
            AccesssRecordset.Update();
            CheckFl = true;
        }
        AccesssRecordset.Close();
        db.Close();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    finally
    {
       System.Runtime.InteropServices.Marshal.ReleaseComObject(dbEngine);
    }
}
I've tried this solution too: How to repair COMException error 80040154?
It still works on my computer, but on no other one. And I don't know how to make all the manipulation on the registry on each computer to make it works (I don't want this solution either since it would be a very huge amount of time)
I know this is a 32-64 bit problem somewhere, but event the x86 build don't works on other computer... How should I resolve this problem ?
This is my second question on this site, please, if something is wrong with my question, tell me, and I will do everything possible to correct it :)
 
     
    