Attach database failed error 9004

Hi,

i need to attach my db, but i receive this error:

an error occurred while processing the log for database 'xyj'.

Could not open database 'xyj' . Create database is aborted. (Microsoft Sql Server,

error 9004).

Can you help me?

[270 byte] By [Gigi69] at [2008-2-16]
# 1

You have two options:

  1. You can create an empty database with the same name and physical file layout, shut down the server, swap in the files you want to attach in place of the empty DB files, and start the server. The database should come up in suspect mode. You can then ALTER DATABASE <foo> SET EMERGENCY to put it in emergency mode, and then run DBCC CHECKDB REPAIR_ALLOW_DATA_LOSS. This will pull as much data as possible out of the log to make the database consistent, but may have to delete some data in order to make the database consistent. This is the option which is most likely to get the maximum data back.
  2. You can attempt to use the CREATE DATABASE FOR ATTACH_REBUILD_LOG to see if that will bring it back. If the database was cleanly shut down, you MIGHT be able to succeed. There is also the chance that the database will be inconsistent or corrupt if there are transactions which could not be rolled back. You should in any event run DBCC CHECKDB REPAIR_ALLOW_DATA_LOSS to make your database consistent. In this event, SQL Server will make no attempt to mine information from the log. It will ignore the contents of the log. If there were transactions in process no rollback will be possible, so the ALLOW_DATA_LOSS will be required.

KevinFarlee at 2007-8-30 > top of Msdn Tech,SQL Server,SQL Server Disaster Recovery and Availability...
# 2

hi gigi,

could it be that

sql server wasn't able to find

the log in the same directory as the db file.

you can use enterprise manager to point to the log files

or specify the location of the log files in the sp attach db command

EXEC sp_attach_db @dbname = N'pubs', 

@filename1 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf',

@filename2 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs_log.ldf'

regards

joeydj at 2007-8-30 > top of Msdn Tech,SQL Server,SQL Server Disaster Recovery and Availability...
# 3

Dear Kevin,

i want to thank you very much for your help... the db is ok now...

Best regards

Gigi

Gigi69 at 2007-8-30 > top of Msdn Tech,SQL Server,SQL Server Disaster Recovery and Availability...
# 4

Dear joeydj,

i want to thank you very much for your help... the db is ok now...

Best regards

Gigi

Gigi69 at 2007-8-30 > top of Msdn Tech,SQL Server,SQL Server Disaster Recovery and Availability...
# 5

I have these exact problem but on sql server 2000.

client was not backing up databases and after a power glitch, there is disk corruption - all the files are on the file system but I cannot start the instance

i tried to attach any of the user database files to another instance on another box and get the same error

Error: 9004 An error occurred while processing the log for database

Now, databases were in full recovery mode, no backups ... please advice

sql server 2000 sp4

maiko at 2007-8-30 > top of Msdn Tech,SQL Server,SQL Server Disaster Recovery and Availability...
# 6
have these exact problem but on sql server 2000.

client was not backing up databases and after a power glitch, there is disk corruption - all the files are on the file system but I cannot start the instance

i tried to attach any of the user database files to another instance on another box and get the same error

Error: 9004 An error occurred while processing the log for database

Now, databases were in full recovery mode, no backups ... please advice

sql server 2000 sp4

maiko at 2007-8-30 > top of Msdn Tech,SQL Server,SQL Server Disaster Recovery and Availability...
# 7

hi maiko,

the solution that i used to solve my proble was:

- create a new db with the same name of the lost db;

- put the db in emergency mode;

- stop sql service and replace the mdf file;

- start sql service;

- the db is probably corrupted for the disk crash...and you have to reindex all table.

bye

Gigi

Gigi69 at 2007-8-30 > top of Msdn Tech,SQL Server,SQL Server Disaster Recovery and Availability...
# 8
Thanks Kevin.
Your suggestion saved me.
I did not follow it completely but it point me the right direction.

I had an other machine that crashed, I had the mdf and log file, but the new system did not want to import it.
Also it did refuse to restore the backup because it was a different database (through it had the smae data structure).
After swapping the files, I was able to restore from the backup
Thanks a lot
RNBY

rnby at 2007-8-30 > top of Msdn Tech,SQL Server,SQL Server Disaster Recovery and Availability...

SQL Server

Site Classified