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


Add to briefcase 12»»

Attach MDF file with no LOG Expand / Collapse
Author
Message
Posted Tuesday, February 7, 2006 11:22 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 11, 2006 8:32 AM
Points: 3, Visits: 1

Greetings,

I'm trying to attach a MDF file with no LOG (log file has been deleted). Normally SQLServer creates a new LOG file. But this time I get this message:

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

There is no FCT_ENTIDADES_Log.LDF in the Data directory.

Can someone give me a hand on this?

Thanks

 

 

Post #256497
Posted Tuesday, February 7, 2006 11:46 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, August 18, 2014 12:57 PM
Points: 1,295, Visits: 783

Hello,

execute this query with the respective information

EXEC sp_attach_single_file_db @dbname = '', --- your database name
   @physname = '' --- the location of the .mdf file

Thanks and have a nice day!!!




Lucky
Post #256502
Posted Tuesday, February 7, 2006 11:52 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 11, 2006 8:32 AM
Points: 3, Visits: 1

Hi.

Thank you for replying.

That's precisely the script i'm executing...

 

Post #256505
Posted Tuesday, February 7, 2006 11:59 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, August 18, 2014 12:57 PM
Points: 1,295, Visits: 783

Then you try to attach the same through Enterprise Manager.

Right Click on databases -> all tasks -> attach database

a new window will be opened. Give the location of the .mdf file

In the next block, you can see the original file names and physical file names. here you uncheck the .ldf file and speacigy the database name to attach as and the database owner.

Hope it will work now.




Lucky
Post #256509
Posted Tuesday, February 7, 2006 12:02 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, October 11, 2006 8:32 AM
Points: 3, Visits: 1

Hello.

I've this one indeed. But i obtain the same message in the dialog box.

Thanks for your help.

Post #256510
Posted Wednesday, February 15, 2006 11:16 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Saturday, October 6, 2012 10:44 AM
Points: 133, Visits: 286

When u attach the db with no log file, the device activation error occurs and sql server creates a new log file..

After executing the attach statement, exec sp_helpdb 'dbname' should give you the locations of the files..

 



-Krishnan
Post #258771
Posted Thursday, February 23, 2006 5:42 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, June 10, 2014 4:50 PM
Points: 324, Visits: 217
If the files were not detached (using sp_detach_db) succesfully then you cannot not use sp_attach_db. The key here is detached "successfully".


Post #261182
Posted Thursday, March 30, 2006 7:34 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, April 4, 2006 12:17 PM
Points: 25, Visits: 1

Correct me if I am wrong, but if the database originally had more than one physical file for the log then attach command will not recreate the log file.  This only seems to work if you have only one physical file for your log.  At least that has been the case for me.

Post #269811
Posted Friday, March 31, 2006 8:56 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 7:29 PM
Points: 344, Visits: 289

There is no easy way of doing it.

I am sure that database was not cleanly shutdown so you won't be able to use only mdf file to recover the database (sp_attach_single_file_db)

Do below steps.

  • Run the command for MDF file and get the logical and physical name of Log file.

== I detached ran for pubs database files==

DBCC CHECKPRIMARYFILE('C:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf', 3)

  • Create a database with same physcial and logical file name.
  • Stop SQL Server.
  • Keep old mdf file on same location as of new database and rename log file.
  • Start SQL Server.
  • Database would come up in suspect mode.
  • Since Log File will not be linked to the new MDF File you have to run DBCC REBUILD_LOG

    dbcc rebuild_log('dbname','New Log File NAme')

  • THIS IS UNDOCUMENTED COMMAND.

  • database will come into Single User mode

  • Run dbcc checkdb and if there are problems then you need to restore from backup

 

HTH

 

 

Post #270208
Posted Friday, March 31, 2006 2:24 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, June 10, 2014 4:50 PM
Points: 324, Visits: 217
This would have been good information to know two months ago. I love undocumented commands, especially when they have been documented.


Post #270305
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse