Sign in to follow this  
UnshavenBastard

[.net] Re-Opening of a secured Access DataBase fails

Recommended Posts

Hi, this is strange. I open an MS Access DataBase, using it and stuff, then, in the program, there's an option to ex-/import the *.mdb data base file. The data base connection normally lasts as long as the program is running, but in this case, I thought it could make sense to close, import, and then reopen the connection to that mdb file ;) The data base is secured with a security.mdw file, and, after my attempt to reopen the thing, I get this error: "Can't connect to data base. The work group's information file is missing or opened exclusively by another user." (this might not be the exact message you'd get on an english system. I translated.) This is what I'm doing:
void open()
{
try
{		
    connection = new OleDbConnection(m_constring);
    connection.Open();
}	
catch(Exception exp)
{
    MessageBox.Show(exp.Message);
}

}

void close()
{
    if (connection.State == ConnectionState.Open)
        connection.Close();
}

Now, I think it would make much sense if the connection object also closed the damn security file when I call Close(), right? But it seems not to do so, or what the heck is going on there? thanks in advance for your hints, unshaven

Share this post


Link to post
Share on other sites
paulecoyote    1065
Access is a bit crappy at this kind of thing. Put your close in a try... catch block - ignore any exceptions - so you attempt to close it regardless.

If any part of your program has a file lock (even a open dialog) it will fail because it wants exclusive access to it. Ensure that you don't have any rogue references to the file anywhere.

I'd consider using MSDE - it's free cut down version of SQL Server. Using some other free MS tools (IE WebMatrix) lets you legitimately distribute the MSDE too.

Share this post


Link to post
Share on other sites
Doesn't work...

Quote:

Access is a bit crappy at this kind of thing. Put your close in a try... catch block - ignore any exceptions - so you attempt to close it regardless.


you mean, like this?:


public void close()
{
try
{ if (connection.State == ConnectionState.Open)
connection.Close();
}catch (Exception ex)
{
}
finally
{ connection.Dispose(); // shouldn't at least this close the thing???
connection = null; // I whack you!
}
}






Quote:

If any part of your program has a file lock (even a open dialog) it will fail because it wants exclusive access to it. Ensure that you don't have any rogue references to the file anywhere.


Can't find one...
Damn it.

Btw, after importing the file, closing and restarting the program again, everything works just fine. So the file isn't crippled or something.

Share this post


Link to post
Share on other sites
hahah..... :grin:

me fooooool !


just for developing/testing, I set as the path of that mdw file in a string @"..\..\security.mdw", where the file, relative from the *.exe, is located.

It seems the file dialog for chosing where to place/take from the data base file for ex-/importing changes the current path,
so, the mdw cannot be found.

I just typed in the complete path, now it works :grin:

Thanks anyway!
Have a nice day.

- unshaven

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this