Closing Access file created with ADOX.CatalogClass

Discussion in 'Microsoft C# .NET' started by VMI, Jan 13, 2005.

  1. VMI

    VMI Guest

    I'm creating an Access file with the following code, but won't let me erase
    it after creating it. How can I close the file immediately after creating
    it?

    ADOX.CatalogClass cat = new ADOX.CatalogClass();
    cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
    "Data Source=" + sFileName + ";" +
    "Jet OLEDB:Engine Type=5");
    cat=null; // Does NOT work



    Thanks.
     
    VMI, Jan 13, 2005
    #1
    1. Advertisements

  2. Hi,

    Try this:

    Marshal.ReleaseComObject(cat);
    cat = null;
    GC.Collect(); // This is the last resort - don't use if ReleaseComObject
    alone helps.

    --
    Sincerely,
    Dmitriy Lapshin [C# / .NET MVP]
    Bring the power of unit testing to the VS .NET IDE today!
    http://www.x-unity.net/teststudio.aspx

    "VMI" <> wrote in message
    news:Oi1wVWZ%...
    > I'm creating an Access file with the following code, but won't let me
    > erase it after creating it. How can I close the file immediately after
    > creating it?
    >
    > ADOX.CatalogClass cat = new ADOX.CatalogClass();
    > cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
    > "Data Source=" + sFileName + ";" +
    > "Jet OLEDB:Engine Type=5");
    > cat=null; // Does NOT work
    >
    >
    >
    > Thanks.
    >
    >
    >
     
    Dmitriy Lapshin [C# / .NET MVP], Jan 14, 2005
    #2
    1. Advertisements

  3. VMI

    VMI Guest

    It worked. Thanks.


    "Dmitriy Lapshin [C# / .NET MVP]" <> wrote
    in message news:%231DRk9i%...
    > Hi,
    >
    > Try this:
    >
    > Marshal.ReleaseComObject(cat);
    > cat = null;
    > GC.Collect(); // This is the last resort - don't use if ReleaseComObject
    > alone helps.
    >
    > --
    > Sincerely,
    > Dmitriy Lapshin [C# / .NET MVP]
    > Bring the power of unit testing to the VS .NET IDE today!
    > http://www.x-unity.net/teststudio.aspx
    >
    > "VMI" <> wrote in message
    > news:Oi1wVWZ%...
    >> I'm creating an Access file with the following code, but won't let me
    >> erase it after creating it. How can I close the file immediately after
    >> creating it?
    >>
    >> ADOX.CatalogClass cat = new ADOX.CatalogClass();
    >> cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
    >> "Data Source=" + sFileName + ";" +
    >> "Jet OLEDB:Engine Type=5");
    >> cat=null; // Does NOT work
    >>
    >>
    >>
    >> Thanks.
    >>
    >>
    >>

    >
     
    VMI, Jan 14, 2005
    #3
  4. VMI

    FishDawg

    Joined:
    Jun 15, 2005
    Messages:
    1
    Likes Received:
    0
    Release and unlock an Access database file (.mdb) created using ADOX

    When you create the database, a connection is created to the database automatically. You must close the connection to release the lock on the file. The connection is in the catalog's ActiveConnection property.

    Using COM references:
    1) Microsoft ActiveX Data Objects 2.8 Library
    2) Microsoft ADO Ext. 2.8 for DDL and Security

    Sample code:

    private void CreateDatabaseFile(string filename)
    {
    ADOX.CatalogClass catalog = new ADOX.CatalogClass();
    catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename + ";Jet OLEDB:Engine Type=5");

    ADODB.Connection connection = catalog.ActiveConnection as ADODB.Connection;
    if (connection != null)
    {
    connection.Close();
    }
    catalog.ActiveConnection = null;
    catalog = null;
    }
     
    Last edited: Jun 15, 2005
    FishDawg, Jun 15, 2005
    #4
  5. VMI

    haggy

    Joined:
    Apr 10, 2006
    Messages:
    1
    Likes Received:
    0
    I have the some problem but this solution doesn't work for me. I want to destroy database that i create but i can't. I get this exception:

    Additional information: The process cannot access the file "C:/.../vIP." because it is being used by another process.

    The code that I use is:

    *****************************************************
    ADOX.CatalogClass catalog = new ADOX.CatalogClass();


    catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +

    "Data Source=C:/.../vIP.;" + "Jet OLEDB:Engine Type=5");


    System.Runtime.InteropServices.Marshal.ReleaseComObject(catalog);

    catalog =
    null;

    GC.Collect();



    System.IO.File.Delete("C:/.../vIP.");

    ******************************************************

    I now that this problem cause ADOX.CatalogClass catalog because without it, it works, but in that case I create database manual and this is not good choice for me.

    Please help. Thanks.
     
    haggy, Apr 11, 2006
    #5
  6. VMI

    vinodgs

    Joined:
    Nov 30, 2007
    Messages:
    1
    Likes Received:
    0
    haggy did you got the solution to destroy database

    hi,

    did you got the solution to destroy database.

    if so, please reply!

    Thanks
     
    vinodgs, Nov 30, 2007
    #6
  7. VMI

    mihiran

    Joined:
    Mar 16, 2013
    Messages:
    1
    Likes Received:
    0
    I recently experienced this problem.If your development machine is 32 bit while production machine is 64 bit then following code may just save your day!
    if (IntPtr.Size == 8)//if the os is 64 bit
    {
    ADOX.CatalogClass cat = new ADOX.CatalogClass();
    cat.Create("Provider=Microsoft.ACE.OLEDB.12.0;" +
    "Data Source=E:\\new folder\\yourfilename.mdb;" +
    "Jet OLEDB:Engine Type=5");
    cat = null;
    }
    else
    {
    if (IntPtr.Size == 4)//if the os is 32 bit
    {
    ADOX.CatalogClass cat = new ADOX.CatalogClass();
    cat.Create("Provider=Microsoft.Jet.OLEDB.4.0;" +
    "Data Source=E:\\new folder\\yourfilename.mdb;" +
    "Jet OLEDB:Engine Type=5");
    cat = null;
    }
     
    mihiran, Mar 16, 2013
    #7
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Developer98115

    Getting schema information in C# using ADOX

    Developer98115, Sep 19, 2003, in forum: Microsoft C# .NET
    Replies:
    2
    Views:
    226
    Robert Havens
    Sep 20, 2003
  2. Oliver
    Replies:
    0
    Views:
    400
    Oliver
    Oct 17, 2003
  3. Randy

    ADOX

    Randy, Sep 20, 2004, in forum: Microsoft C# .NET
    Replies:
    1
    Views:
    253
    Miha Markic [MVP C#]
    Sep 21, 2004
  4. Randy

    ADOX

    Randy, May 3, 2005, in forum: Microsoft C# .NET
    Replies:
    0
    Views:
    207
    Randy
    May 3, 2005
  5. Randy

    ADOX CatalogClass - File release

    Randy, May 10, 2005, in forum: Microsoft C# .NET
    Replies:
    0
    Views:
    405
    Randy
    May 10, 2005
Loading...

Share This Page