Current users and Repair

C

canann

Can anyone show me how to programatically list the current users of an .mdb
(2000) file when it is open.

Any if anyone has a snippet to REPAIR a database progamatically that would
be great.

I need this in c# but will take it vb .

Thanks in advance
 
C

canann

Thanks Douglas, I have looked at the first solution and am converting it run
under (VS C#) .


Can you explain how to -

{You can create a shortcut that allows the user to
run repair on the database should they get prompted for it. }

I have an application (VS C#) that uses Access as a shared db. When the file
is corrupt I would like for any of the users to be able to repair/compact.

The users will not have Access installed - the admin does have Access
installed.


Any help would be appreciated.
 
D

Douglas J. Steele

If the users don't have Access installed, then they won't be able to do it
using a shortcut as I originally suggested. Do you have a reference set to
DAO? If so, you might be able to use the RepairDatabase method of the
DBEngine object. It's as simple as:

DBEngine.RepairDatabase dbname

The dbname argument is a String that is the path and file name for an
existing Microsoft Jet database file. If you omit the path, only the current
directory is searched. If your system supports the uniform naming convention
(UNC), you can also specify a network path, such as
"\\server1\share1\dir1\db1.mdb".

From the Help file:

"You must close the database specified by dbname before you repair it. In a
multiuser environment, other users can't have dbname open while you're
repairing it. If dbname isn't closed or isn't available for exclusive use,
an error occurs.

This method attempts to repair a database that was marked as possibly
corrupt by an incomplete write operation. This can occur if an application
using the Microsoft Jet database engine is closed unexpectedly because of a
power outage or computer hardware problem. The database won't be marked as
possibly corrupt if you use the Close method or if you quit your application
in a usual way.

The RepairDatabase method also attempts to validate all system tables and
all indexes. Any data that can't be repaired is discarded. If the database
can't be repaired, a run-time error occurs.

When you attempt to open or compact a corrupted database, a run-time error
usually occurs. In some situations, however, a corrupted database may not be
detected, and no error occurs. It's a good idea to provide your users with a
way to use the RepairDatabase method in your application if their database
behaves unpredictably.

Some types of databases can become corrupted if a user ends an application
without closing Database or Recordset objects and the Microsoft Jet database
engine; Microsoft Windows doesn't have a chance to write data caches to
disk. To avoid corrupt databases, establish procedures for closing
applications and shutting down systems that ensure that all cached pages are
saved to the database. In some cases, power supplies that can't be
interrupted may be necessary to prevent accidental data loss during power
fluctuations.

Note After repairing a database, it's also a good idea to compact it using
the CompactDatabase method to defragment the file and to recover disk
space."

Depending on what version of Jet was used to create the database file, you
might be able to use JetComp.exe. See
http://support.microsoft.com/kb/295334/EN-US/ for details (and while it
doesn't list it, it should work with Access 2003 as well)

Generically, you may find the Corrupt Microsoft Access MDBs FAQ that Tony
Toews has at http://www.granite.ab.ca/access/corruptmdbs.htm interesting
reading, as well as http://www.datarevive.com/repair.htm
 
D

David W. Fenton

I have an application (VS C#) that uses Access as a shared db.
When the file is corrupt I would like for any of the users to be
able to repair/compact.

Use DAO's CompactDatabase command. If you're using ADO, then you'll
have to use JRO for that.

But you really need to make sure you're not running your app in an
environment that is unsuitable for Jet. If you're just planning for
something that might happen once in a blue moon, sure, OK. But if
you are experiencing frequent corruptions, then that's a different
story entirely and you need to figure out what's causing the
corruption and fix that problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top