October 4, 2005 at 12:01 am
Hi,
I accidentally deleted the Transaction log file(Shift delete). Now I am not able to attach the database without this log file. Is there any way by which this is possible ??
October 4, 2005 at 3:50 am
Hi,
There shouldn't be too much of a problem, just go ahead and re-attach, SQL will see that the transaction log file is missing and should recreate it for you.
October 4, 2005 at 3:56 am
Hi Mike,
I tried doing it but it throws up an error and it does not create a new Log file for me. Can U try it in ur machine and update me? Thanks in Advance....
October 4, 2005 at 4:27 am
Hi there,
You can have a look in books online for the correct syntax, or failing that here's something that should do it for you using SQLDMO inside a script file.
Basically create an empty text file and copy everything between the lines (but not including the lines). Obviously you'll need to amend the name of the DB and the location of the file etc (the bits in blue) but that's not exactly rocket science.
Rename the file to attach.vbs and run it
--------------------
on error resume next
dim oSQL
dim oDB
dim strDBName
strDBName = "YourDB"
strLogin = "sa"
strPassword = "yourpassword"
strMDFFile = "c:\datafile\YourDB_Data.mdf"
set oSQL = createobject("SQLDMO.SQLServer")
oSQL.Connect "(local)", strLogin , strPassword
set oDB = oSQL.Databases.Item(strDBName )
if isobject(oDB) then
msgbox "database already exists"
else
oSQL.AttachDB strDBName, strMDFFile
msgbox "done"
end if
-----------------------------------
October 5, 2005 at 12:34 am
You can use the stored proc
sp_attachsinglefiledb
Copied from books online...
Attaches a database having only one data file to the current server.
sp_attach_single_file_db [ @dbname = ] 'dbname'
, [ @physname = ] 'physical_name'
[@dbname =] 'dbname'
Is the name of the database to be attached to the server. dbname is sysname, with a default of NULL.
[@physname =] 'phsyical_name'
Is the physical name, including path, of the database file. physical_name is nvarchar(260), with a default of NULL.
0 (success) or 1 (failure)
None
When sp_attach_single_file_db attaches the database to the server, it builds a new log file and performs additional cleanup work to remove replication from the newly attached database.
Use sp_attach_single_file_db only on databases that were previously detached from the server using an explicit sp_detach_db operation.
Use sp_attach_single_file_db only on databases that have a single log file. Do not use this stored procedure on databases that have multiple log files.
Only members of the sysadmin and dbcreator fixed server roles can execute this procedure.
This example detaches pubs and then attaches one file from pubs to the current server.
EXEC sp_detach_db @dbname = 'pubs'EXEC sp_attach_single_file_db @dbname = 'pubs', @physname = 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf'
©1988-2004 Microsoft Corporation. All Rights Reserved.
November 2, 2007 at 3:36 am
Thank you for the attach_db explanation!:D It really worked!
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply