I am developing a small tool in C # to convert a base mdb accdb. It must run on a windows server.
To do this I use the Microsoft.Office.Interop.Access.dll
The problem is that when I want to launch the application :
accessApp = new Microsoft.Office.Interop.Access.Application();
i have the following error :
The class factory recovery was added to the CLSID error {73A4C9C1-D68D-11D0-98BF-00A0C90DC8D9} because of the following error: 80040154 Class not registered (Exception HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
I saved the dll with the Regasm command but it the same thing.I also tried to launch in x86, x64 and any CPU.
The completed code :
class Program
{
public static Access.Application accessApp { get; set; }
static void Main(string[] args)
{
try
{
accessApp = new Microsoft.Office.Interop.Access.Application();
accessApp.Visible = true;
string sourceFile = @"D:\Biwee\Bases\styzan.mdb";
string desFile = @"D:\Biwee\Bases\database3.accdb";
//CompactAndRepair(sourceFile, accessApp);
accessApp.ConvertAccessProject(sourceFile, desFile, Access.AcFileFormat.acFileFormatAccess2007);
accessApp.Quit();
}
catch(Exception message)
{
var error = message;
Console.WriteLine("Erreur : " + message);
Console.Read();
if(accessApp != null)
accessApp.Quit();
}
Console.Read();
}
public static void CompactAndRepair(string accessFile, Access.Application app)
{
string tempFile = Path.Combine(Path.GetDirectoryName(accessFile),
Path.GetRandomFileName() + Path.GetExtension(accessFile));
app.CompactRepair(accessFile, tempFile, false);
app.Visible = false;
FileInfo temp = new FileInfo(tempFile);
temp.CopyTo(accessFile, true);
temp.Delete();
}
}
Thank you for your help.
ANSWER :
the solution is the following one, it is necessary to use the Access Database Engine 2010 (x86 or 64) which manages the mdb and accdb.
The code is as follows:
object[] args = new object[2]
{
(object) SourceDbMDB,
(object) DestDbACCDB
};
object instance = Activator.CreateInstance(Type.GetTypeFromProgID("DAO.DBEngine.120"));
instance.GetType().InvokeMember("CompactDatabase", BindingFlags.InvokeMethod, (Binder)null, instance, args);
Marshal.ReleaseComObject(instance);
I developed an application to run the conversion (open the first time as an administrator to install the engine if necessary);
Then just run the following command in cmd:
call "ExePath" "MdbPath"
User contributions licensed under CC BY-SA 3.0