SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On



Can I attach a database with only the mdf file? Expand / Collapse
Author
Message
Posted Monday, January 30, 2006 8:35 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, February 06, 2006 3:10 AM
Points: 2, Visits: 1

Hi,

our forum server suffered a catastrophic failure, which included the RAID failing too.

I only have the mdf file, no ldf file. I did not unmount the db, or do a single file unmount. I've tried a few things to reattach it, but no joy.

Any ideas would be appreciated.

Thanks

Post #254444
Posted Monday, January 30, 2006 8:52 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, March 15, 2010 10:58 AM
Points: 1,279, Visits: 574

Hello Howard,

Yes, you can attach a database with .mdf file but you will loose all the transactions, which have not been committed to the database.

SQL Server will create a new .ldf file when you attach a database with a single file (.mdf).

Syntax for attaching the single file:

sp_attach_single_file_db [ @dbname = ] 'dbname'
    ,
[ @physname = ] 'physical_name'

Thanks and have a nice day!!!




Lucky
Post #254447
Posted Monday, January 30, 2006 9:23 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, February 06, 2006 3:10 AM
Points: 2, Visits: 1

I tried that already with:

 

EXEC sp_attach_single_file_db @dbname = 'koiforum',
   @physname = 'C:\Program Files\Microsoft SQL Server\MSSQL$LISTSERVER\data\koiforum_data.mdf'

 

I get this error:

Server: Msg 1813, Level 16, State 2, Line 1
Could not open new database 'koiforum'. CREATE DATABASE is aborted.
Device activation error. The physical file name 'C:\Program Files\Microsoft SQL Server\MSSQL$LISTSERVER\data\KoiForum_Log.LDF' may be incorrect.

 

Any ideas?

 

Thanks

Post #254457
Posted Monday, January 30, 2006 10:17 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, March 15, 2010 10:58 AM
Points: 1,279, Visits: 574

Hello Howard,

Are you sure that you have the .mdf file. B'cos in the syntax you are mentioning the .mdf file but the error is pointing that .ldf file is incorrect.

Please go through this article

http://www.sqlservercentral.com/columnists/ckempster/deattachandreattachdatabases.asp

Thanks and have a nice day!!!




Lucky
Post #254470
Posted Wednesday, February 01, 2006 2:50 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, March 12, 2010 7:51 AM
Points: 97, Visits: 36

This is the syntax that I use to attach a DB with only a MDF file:

Exec sp_attach_single_file_db DB_Name, 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\DB_Name_Data.MDF'

Just change the highlighted portions. 

Matt

Post #255085
Posted Tuesday, February 07, 2006 4:06 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Wednesday, September 24, 2008 4:22 AM
Points: 90, Visits: 4
If your database was not detached using sp_detach_db or your server was not shutted down cleanly you CAN'T use sp_atach_single_file_db.

Still, there is a workarround on this. I did use once the "dbcc rebuild_log" command to rebuild the ldf file, but my database become inconsistent. But I managed to copy most of my important data.
If your data was so important you should had a backup plan for it.
Post #256307
« Prev Topic | Next Topic »


Permissions Expand / Collapse