Solved

SQL database

Posted on 2009-05-10
15
808 Views
Last Modified: 2013-12-07
Need some help does anyone knows how i can recover a mdf file.  I have a few databases but one of them give me error when i want to attatch to SQL. I have the MDF e LDF files but need help to detect and correct those erros in a way that i can attatch without problems.
0
Comment
Question by:naptor
  • 8
  • 7
15 Comments
 
LVL 6

Expert Comment

by:bull_rider
ID: 24351395
Before follwing these steps please take a backup of thh existing mdf and ldf files.1. Create a new database with same MDF and LDF name2. Stop sql server and delete the new MDF file and copy the old MDF file3. Start SQL Server and verify the status of the database. If the database status is suspect do the following scripts in Query Analyzer:
a. Override updates in Master Table

    Use Master
    Go
    sp_configure 'allow updates', 1
    reconfigure with override
    Go

b. Get the value of the status column in sysdatabases table

    select * from sysdatabases where name = 'db_name'
    -- note the value of the status column for later use in # f
    begin tran

c. Set status of the database to suspect (32768)

    update sysdatabases set status = 32768 where name ='db_name'
    commit tran

d. Rebuild transaction log

    DBCC rebuild_log('db_name','db_log_path')

e. Set the database to single user access

    sp_dboption '', 'single user', 'true'
    DBCC checkdb('db_name')
    Go

f. Restore the status of the database in sysdatabases table

    begin tran
    update sysdatabases set status = previous_value where name = 'db_name'


    -- verify one row is updated before committing
    commit tran
    Go

g. Restore the override property of Master table

    sp_configure 'allow updates', 0
    reconfigure with override
    Go

4. Now open or refresh the enterprise manager you can now see the tables inside the fixed database.

If any problems still persist, you can import all tables into temporary database and drop the original database. Create a new database with same name then re-import all the tables from the temporary database.

Hope this solves your issue. :)
0
 

Author Comment

by:naptor
ID: 24364743
i tryied to do the process but on line b got this error " Server: Msg 207, Level 16, State 3, Line 1
Invalid column name 'MARPINO'. "

Help needed
0
 
LVL 6

Expert Comment

by:bull_rider
ID: 24364852
Can you tell me on which step you encountered this error? or which statement gave this error?
0
 

Author Comment

by:naptor
ID: 24364954
this error is on statement b. Get the value of the status column in sysdatabases table

   select * from sysdatabases where name = 'db_name'
   -- note the value of the status column for later use in # f
   begin tran
0
 
LVL 6

Expert Comment

by:bull_rider
ID: 24365645
I think you are executing the it without single quotes

Try this:

select * from sysdatabases where name = 'MARPINO'
0
 
LVL 6

Expert Comment

by:bull_rider
ID: 24365699
And that too that should be run under master database
0
 

Author Comment

by:naptor
ID: 24365871
now i have a problem in - e. Set the database to single user access

   sp_dboption '', 'single user', 'true'
   DBCC checkdb('db_name')
   Go
 error

Server: Msg 15010, Level 16, State 1, Procedure sp_dboption, Line 71
The database '' does not exist. Use sp_helpdb to show available databases.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 6

Expert Comment

by:bull_rider
ID: 24366006
Oops my mistake that should be :

sp_dboption 'MARPINO', 'single user', 'true'
   DBCC checkdb('MARPINO')
   Go

0
 

Author Comment

by:naptor
ID: 24366029
after that error

Server: Msg 945, Level 14, State 2, Line 1
Database 'MARPINO' cannot be opened due to inaccessible files or insufficient memory or disk space.  See the SQL Server errorlog for details.
Server: Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.
sp_dboption command failed.
Server: Msg 945, Level 14, State 2, Line 2
Database 'MARPINO' cannot be opened due to inaccessible files or insufficient memory or disk space.  See the SQL Server errorlog for details.
0
 
LVL 6

Expert Comment

by:bull_rider
ID: 24366095
2. Stop sql server and delete the new MDF file and copy the old MDF file

In this step did you copy the old LDF file as well. If not please do so and then try. I forgot to add teh LDF thing there. I apologize.
0
 

Author Comment

by:naptor
ID: 24370071
error after

Server: Msg 926, Level 14, State 1, Line 1
Database 'MARPINO' cannot be opened. It has been marked SUSPECT by recovery. See the SQL Server errorlog for more information.
Server: Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.
sp_dboption command failed.
Server: Msg 926, Level 10, State 1, Line 2
Database 'MARPINO' cannot be opened. It has been marked SUSPECT by recovery. See the SQL Server errorlog for more information.
0
 
LVL 6

Accepted Solution

by:
bull_rider earned 500 total points
ID: 24370975
Please follow the steps to recover a suspect database
EXEC sp_resetstatus 'MARPINO'

ALTER DATABASE MARPINO SET EMERGENCY

DBCC checkdb('MARPINO')

ALTER DATABASE MARPINO SET SINGLE_USER WITH ROLLBACK IMMEDIATE

DBCC CheckDB ('MARPINO', REPAIR_ALLOW_DATA_LOSS)

ALTER DATABASE MARPINO SET MULTI_USER

Open in new window

0
 
LVL 6

Expert Comment

by:bull_rider
ID: 24387103
Did this issue get resolved? If so could you please mark it as answered?
0
 

Author Comment

by:naptor
ID: 24468388
bull_rider    

thanks for the supplied support but i think the log file as errors and a friend recovered the database
0
 

Author Closing Comment

by:naptor
ID: 31579951
for the quick help given to this question  thanks
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle 10g standard edition server with 4 processors 3 36
TSQL - IF ELSE? 3 29
T-SQL: Nested CASE Statements 4 24
MSSQL: Substring and Charindex error 7 18
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now