views:

349

answers:

5

I have an Access application that use the classical front-end/back-end approach. Yesterday, the backend got corrupted for a reason I don't know. So I opened the backend with Access 2003 and access asked me if I wanted to repair the file, I said yes and it seemed to work.

I can open the database see the tables contents and run most of the queries.

However there is an access query that doesn't work with a specific where clause.

Example :

// This works in the original DB, but not in the compacted one :
SELECT a, b, c 
FROM tbl1 INNER JOIN tbl2 ON tbl1.d = tbl2.d 
WHERE e = 3 AND tbl2.f = 1;

// This works in both the original and the compacted one :
SELECT a, b, c 
FROM tbl1 INNER JOIN tbl2 ON tbl1.d = tbl2.d 
WHERE e = 3;

When I try to run the queries, nothing happens. The access process start to use most of the CPU and the GUI stop responding. If I run the query from the query editor, I can use Ctrl+Break to stop the execution. I tried to give the query lot of time and it didn't help.

I've checked the execution plan in showplan.out and it seems correct (at least it should not takes forever to execute)

I tried to compact the DB again. I tried to import the tables in a new DB. I even tried to import the tables and their data in a mdb file that was in a now good state (from a backup).

Anyone have an idea?

+1  A: 

I don't know what type of meta data Access brings along when it imports a table from one database into another one. If the meta data is corrupted, importing the table to another database wouldn't necessarily resolve the problem. If practical, you might try creating the tables from scratch in a brand new database and then just exporting and importing (or copying and paste appending) the data into the new database.

I've never seen a table get corrupted like this in such a small database, although with Access anything is possible. Could there be something wrong with the data?

John M Gant
Thanks for your suggestion. It would be great if I could do this, but I need to find a way to automatate this because I have about 60 tables with lots of relations between them.
Mathieu Pagé
A: 

I'd try recreating the query fresh (new name, etc.), and see what happens.

You could even try copying it (even within the same DB or to a brand new one). If that works, the worst case scenario is you have to copy all the objects across to a new DB.

CodeSlave
already tried this. I imported all objects into a new files, the same problem is still present in the new file.
Mathieu Pagé
And if you recreate that query fresh in a brand new database, linked to the same tables?
CodeSlave
A: 

Do you have access to a SQL Server installation? You could use the Upsizing Wizard under the Tools -> Database Utilities menu to copy the data to SQL Server, and see if you get the same problem there.

John M Gant
-1 Completely useless suggestion.
David-W-Fenton
Hmm... I don't think it's *completely* useless. If you have easy access to a SQL Server installation this is a relatively simple way to rule out the possibility of a data error.
John M Gant
Eh? How does access to a SQL Server do anything for a Jet database?
David-W-Fenton
It doesn't do anything for the Jet database. What it gives you is a relatively easy way to rule out an error in the data. If you port the database to SQL Server and you get the same errors, the problem is most likely with the data rather than with the Jet engine or with the metadata. It's an alternative to what the OP did by moving it to another database, just taking it a step further to isolate the data from the environment. Not a great solution, and probably close to a last resort, but I don't think it's completely useless.
John M Gant
+1  A: 

Sounds like an index was corrupted and when that happens, it's dropped during the compact. Check for a system table called MSysCompactErrors -- you'll have to show hidden objects and/or system objects in Tools | Options | VIEW.

Never compact a Jet MDB without making a backup beforehand. Because of that rule, the COMPACT ON CLOSE function is completely useless, as it's not cancellable, so you always make sure it's turned off in all MDBs.

David-W-Fenton
+1 Good suggestion. Access gives the impression that Compact and Repair is a simple routine operation, but as we see things can go terribly wrong.
John M Gant
Good advice indeed. But in this case, you have to know that I did not had the choice to do the repair, since the data file was corrupted. That being said, it's indeed the compact that caused the problem, because I still get it when I compact a non corrupted version of the file (from a backup).
Mathieu Pagé
Very often much of the data in the pre-compacted corrupted database is still readable. You might try opening it via DAO and seeing if you can read the data you lost. Whether or not this will succeed will depend in part on exactly what caused the corruption.
David-W-Fenton
A: 

Is there an index on the field tbl2.f?

Also try going into that table in datasheet view, sort tbl2.f in ascending sequence and see if there is anything really strange in the first or last records.

Tony Toews