Killing a MDB file

  • Thread starter Thread starter Atley
  • Start date Start date
A

Atley

I am trying to make sure that an MDB is not in use and then delete it. If
it is in use, I want to automatically disconnect all the users and then
delete the file.

Any suggestions are welcome.
 
We have had success using the NetFileClose API. This has the effect
of unlocking the file. But it doesn't tell you if the MDB is in use.

We have a time window and anybody on after that time window can be
disconnected from the MDB at any time.

We have only run it when the mdb is on a server (w2000 but the docs
say it will work on an NT server) and the account running the
NetFileClose is an "operator" on the server.

Notice that the API expects a Unicode string for the servername so the
normal call of (byval str as string) did not work for us.

Public Declare Function NetFileClose lib "netapi32.dll" _
(bvay lpstr as long, byval dword as long) as long

We call it this way

lngreturned = NetFileClose(StrPtr(filename),fileId)

Now the fileid must be obtained from NetFileEenum API and that is not
for the faint of heart.

Before I try to post some code ( I'll have to trim it some since we
have some misc debugging code in here)... Is this something that you
want to get into? I don't know of any other way to kick users out of
a file.

In order to check on whether or not users are really using the MDB
file, I guess you would have to watch the file and check to see if it
was modified in the past X minutes (or set up a FileSystemWatcher
rahter than use the API calls) !!


You can not disconnect the users. They have to close the file.

bceggersATcomcastDOTnet
 
YES PLEASE....

This problem has been a pain in our butts for over a week now... Please
post..


Atley
 
Rather than try to post it all here, see if you can get this zip file

http://home.comcast.net/~bceggers/downloads/unlockfiles.zip

When you run the project, just enter the servername, click on "find
locked files", select a file from the list box and then click on
"unlock selected file" and that should do it for unlocking the file.

Sorry about the choppy-ness of the code but i removed a lot of
debugging code. The tough part is where the CopyMemory is used to
grab selected information that is returned from some of the API calls
(we didn't need it all).

If you have any questions, let me know and I'll see what I can do.

Barry
bceggersATcomcastDOTnet


YES PLEASE....

This problem has been a pain in our butts for over a week now... Please
post..


Atley

bceggersATcomcastDOTnet
 
I tried the code, but even after unlocking the file I cannot delete it
through explorer. Is there something else I have to do to make it so I can
kill this MDB file?

Atley
 
What is the OS of the server with the locked file?
Is the file in a public share?
What are the permissions for your account (admin,operator,power user,
etc)?
Do you have delete rights to that folder and file (when unlocked) ?

Barry

I tried the code, but even after unlocking the file I cannot delete it
through explorer. Is there something else I have to do to make it so I can
kill this MDB file?

Atley

bceggersATcomcastDOTnet
 
What is the OS of the server with the locked file?
Windows 2000 Server
Is the file in a public share? Yes

What are the permissions for your account (admin,operator,power user,
etc)?
Domain Admin
Do you have delete rights to that folder and file (when unlocked) ?
Yes
 
Hi, Atley,

Ok. working under the assumption that Domain Administrators are also
added to the Admin group on the server, the next thing is to put back
some of the debug code that I took out.

I'll try to get it back in this weekend and let you know when I have
the new zip file up for you to download.

It's probably one of the API calls that is failing and the debug code
(not being there...) isn't reporting it. Those failures are usually
due to permissions but that might not be the case here.

I'll be back to you soon.

Sorry for any delay.

Barry



Windows 2000 Server

Domain Admin

Yes

bceggersATcomcastDOTnet
 
HI, Atley,

I added some code to the project to show messageboxes with error
numbers. There is also an .rtf file (CodeDescrription Numbers.rtf)
that will explain the error numbers.

And there is a version that will work in vb.net. Do NOT just use the
conversion wizard to go from vb6 to vb.net.

Here are the two new downloads -

http://home.comcast.net/~bceggers/downloads/unlockfiles_net.zip

http://home.comcast.net/~bceggers/downloads/unlockfiles_vb6.zip

Let me know what error numbers you are getting.

HTH,
Barry

BTW,

Did you convert the project to .NET or did you try it as vb6 ?

Barry



bceggersATcomcastDOTnet

bceggersATcomcastDOTnet
 
Back
Top