Hi
I have a requirement to allow the user to do a 'compact and repair' from the system I have developed. I have looked at some code online and tried the following:
https://www.experts-exchange.com/viewCodeSnippet.jsp?codeSnippetId=10-28247792-1
but this is failing with the following message
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
Any ideas why this is failing? or is there a better method?
Cheers
I have a requirement to allow the user to do a 'compact and repair' from the system I have developed. I have looked at some code online and tried the following:
https://www.experts-exchange.com/viewCodeSnippet.jsp?codeSnippetId=10-28247792-1
but this is failing with the following message
Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.
Any ideas why this is failing? or is there a better method?
Cheers
Code:
using JRO;
private void CompactDatabase(string Path, string Database, string Password="")
{
string Database2 = Database + "1";
string oldmdbfile = "";
string newmdbfile = "";
if (Password != "")
{
oldmdbfile = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path + Database + ";Persist Security Info=True;Jet OLEDB:Database Password='" + Password + "';";
newmdbfile = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path + Database2 + ";Persist Security Info=True;Jet OLEDB:Database Password='" + Password + "';";
}
else
{
oldmdbfile = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path + Database + ";";
newmdbfile = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Path + Database2 + ";";
}
string oldmdbfilepath = Path + Database;
string newmdbfilepath = Path + Database2;
JRO.JetEngine engine = new JetEngine();
engine.CompactDatabase(oldmdbfile, newmdbfile);
File.Delete(oldmdbfilepath);
File.Move(newmdbfilepath, oldmdbfilepath);
MessageBox.Show("Database compact and repaired successfully !");
}