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();
}
[.net] Re-Opening of a secured Access DataBase fails
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:
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
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.
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.
Doesn't work...
you mean, like this?:
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.
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.
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement