Error While Attaching Database MDF File which not have LDF File

When i try to attach mdf file which not have ldf file i got error as follow
The solution is 
Create a new database with the same exact name.
CREATE DATABASE dbname 
GO
Now stop Micrososft SQL Server.
Replace the MDF file with the old MDF file.
Start Micrososft SQL Server.
If everything went well the database should be in "Suspect" mode, which you check by running this:
SELECT DATABASEPROPERTYEX ('YOURDATABASENAME', 'STATUS') AS 'Status';
GO
Your database should now be in 'SUSPECT' mode.
Let's put her in emergency mode:
ALTER DATABASE dbname SET EMERGENCY;
GO
Then single user mode:
ALTER DATABASE dbname  SET SINGLE_USER;
GO
And Finally:
DBCC CHECKDB (dbname , REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL_ERRORMSGS;
GO
In my case when i run this last sql code i got some error and database goes on single user mode and i ran the following code to make it multiuser mode.
ALTER DATABASE dbname 
SET MULTI_USER;
GO
OR you can go to this link and try if this is not helpful for you Click Me

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

Contact Form