Error while opening a connection to MS Access 2007 file: Cannot open the MS Office Access database engine workgroup information file

StackOverflow https://stackoverflow.com/questions/8265293

Domanda

Cannot open the MS Office Access database engine workgroup information file - When I have code as posted.

What I am trying to do in my code is to create MS Access 2007 file and then set the user name and password to it from my program. What am I doing wrong here?

Error occurs here: objOleDbConnection.Open();

EDIT: I have made some changes, seems like it opens a connection but the command is incorrect.

Now problem is here:

        objOleDbCommand.CommandText = 
            "ALTER USER " + storedAuth.UserName + 
            " PASSWORD [" + storedAuth.Password + "] []";

The entire code:

    // 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";
    // Creating command object.
    OleDbCommand objOleDbCommand = new OleDbCommand();
    objOleDbCommand.Connection = objOleDbConnection;

    try
    {
        objOleDbConnection.Open();
        objOleDbCommand.CommandText = "ALTER USER " + 
                    storedAuth.UserName + " PASSWORD [" + 
                    storedAuth.Password + "] []";
        objOleDbCommand.ExecuteNonQuery();
    }
    catch (Exception ex)
    {
        // Displaying any errors that 
        // might have occured.
        MessageBox.Show("Error: " + ex.Message);
    }
    finally
    {
        objOleDbConnection.Close();
    }
È stato utile?

Soluzione

To change an Access DB password, you must it open in exclusive mode. Try adding this to your connection string ;Exclusive=1.

createMSFile.Create("Provider=Microsoft.ACE.OLEDB.12.0;Exclusive=1;Data Source=" +
        sfdNewFile.FileName);

Altri suggerimenti

Well, the error you are getting suggests someone else is keeping the file open, which prevents the password change...

HelpNeeder, I think the problems you are experiencing should first be solved in your other question: Error tells me I haven't close the connection, but haven't I?

Thanks!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top