Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6857261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:59:39+00:00 2026-05-27T01:59:39+00:00

I must have missed something here. I am trying to create a table but

  • 0

I must have missed something here. I am trying to create a table but I am getting an error telling me that connection is still open. But where??? I have re-read the code but I can’t find where the connection is still open…

Problem lays here: objOleDbConnection.Open()

Error say:

You attempted to open a database that is already opened by user 'Admin' on machine 'machine'. Try again when the database is available.

private void sfdNewFile_FileOk(object sender, System.ComponentModel.CancelEventArgs e)
{
    // Creating a ADOX object needed to create
    // new MS Access file.
    ADOX.Catalog createMSFile = new ADOX.Catalog();
    // Creating an object for a table.
    Table nTable = new Table();

    // Creating an object allowing me connecting to the database.
    OleDbConnection objOleDbConnection = new OleDbConnection();
    objOleDbConnection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
            "Data Source=" + sfdNewFile.FileName + ";Persist Security Info=False;Mode=12";
    // Creating command object.
    OleDbCommand objOleDbCommand = new OleDbCommand();
    objOleDbCommand.Connection = objOleDbConnection;

    try
    {
        // Created a new MS Access 2007 file with specified path.
        createMSFile.Create("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
            sfdNewFile.FileName);

        objOleDbConnection.Open();
        objOleDbCommand.CommandText = "CREATE TABLE PersonalData (" +
            "[DataID] AUTOINCREMENT NOT NULL PRIMARY KEY ," +
            "[Type] VARCHAR(40) NOT NULL ," +
            "[URL] VARCHAR(40) NOT NULL ," +
            "[SoftwareName] VARCHAR(40) NOT NULL ," +
            "[SerialCode] VARCHAR(40) NOT NULL ," +
            "[UserName] VARCHAR(40) NOT NULL ," +
            "[Password] VARCHAR(40) NOT NULL";

        objOleDbCommand.ExecuteNonQuery();
    }
    catch (Exception ex)
    {
        // Displaying any errors that 
        // might have occured.
        MessageBox.Show("Error: " + ex.Message);
    }
    finally
    {
        // It is importnat to release COM object, in this very order
        // otherwise we eill end up with an error.
        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(createMSFile);

        // Closing the connection to the database.
        objOleDbConnection.Close();
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T01:59:39+00:00Added an answer on May 27, 2026 at 1:59 am

    It seems that the ADOX object should close its connection as well.
    Look at the following sample from Microsoft:
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms681562(v=vs.85).aspx

    Their ADOX object is named cat.
    They have the following:

    cat.ActiveConnection = Nothing
    

    Which will probably translate to:

    createMSFile.ActiveConnection = null
    

    In your code (probably in the first Finally block).
    I think it’s the ADOX object that makes the difference, before dispoing it, try to set it’s ActiveConnection to null.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I must have missed something obvious, but how do you create a scala-tuple in
I must have missed something regarding generics in Java, but why does this not
Here's another one of these LinqToSQL questions where I'm sure I must have missed
I must have overlooked something completely obvious?? but my button displays its image and
I must have missed something in my LINQ training. In Linq to SQL using
I must have done something wrong. I have a C# project in Visual Studio
Assembly [AssemblyName] must have a shared name to be installed globally I am getting
I'm sure this must have been asked before, but I can't find it. Can
Perhaps I'm misapplying Unity, but here goes. I have a couple of applications, both
I'm sure that I missed something, and that I've got something plain wrong. 1:(0-1)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.