none
Comapacting Access 2003 mde database with password RRS feed

  • Question

  • Hi,

    I'm compacting the mde data base using c#. After compacting my database password was removed. Is there any way to compact the database with password. Kinly guide me to solve this issue.

    Thanks in advance,

    Babu.K

    Monday, September 19, 2011 11:35 AM

Answers

  • Hi Guys,

    I Found the sollution here is my code for that.

     

     

    public static void

    CompactAccessDB()

    {

     

    //create an inctance of a Jet Replication Object

     

    object objJRO = Activator.CreateInstance(Type.GetTypeFromProgID("JRO.JetEngine"

    ));

     

    try

    {

     

    string ConnectionString = UtilityDAL.GetConnString(ApplicationVariables.MainDBPath + "\\" + DBManager

    .MainDBName,

     

    new XMLHelper(ApplicationVariables.XmlSettingFilePath).GetAttributeValue("Database", "type", "Main", "connectionString"

    ));

     

    if (System.IO.File.Exists(ApplicationVariables.MainDBPath + "\\tmp" + DBManager

    .MainDBName))

    {

    System.IO.

    File.Delete(ApplicationVariables.MainDBPath + "\\tmp" + DBManager

    .MainDBName);

    }

     

    //filling Parameters array

     

    object[] oParams = new object[] { ConnectionString, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ApplicationVariables.MainDBPath + "\\tmp" + DBManager.MainDBName +

    ";Jet OLEDB:Engine Type=5;"

    +"Jet OLEDB:Database Password="+DBManager.DBPassword};

     

    //invoke a CompactDatabase method of a JRO object pass Parameters array

    objJRO.GetType().InvokeMember(

    "CompactDatabase", System.Reflection.BindingFlags.InvokeMethod, null

    , objJRO, oParams);

     

    //database is compacted now to a new file let's copy it over an old one and delete it

     

    //System.IO.File.Delete(DBManager.MainDBName);

    System.IO.

    File.Delete(ApplicationVariables.MainDBPath + "\\" + DBManager

    .MainDBName);

    System.IO.

    File.Move(ApplicationVariables.MainDBPath + "\\tmp" + DBManager.MainDBName, ApplicationVariables.MainDBPath + "\\" + DBManager

    .MainDBName);

     

    //clean up (just in case)

    System.Runtime.InteropServices.

    Marshal

    .ReleaseComObject(objJRO);

     

    }

     

    catch (Exception

    ex)

    {}

     

    finally

    {objJRO = null;

    }}

    • Marked as answer by K Babu Monday, September 19, 2011 2:48 PM
    Monday, September 19, 2011 2:47 PM