Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
When i restore my database in sqlserver2005 express and run a new query, sqlserver don't allow login for me.
Below is my code:
SQL
USE MASTER BACKUP DATABASE DB TO DISK ='DB.BAK' WITH INIT;"

SQL
USE MASTER RESTORE DATABASE DB FROM DISK = 'DB.BAK'


I found that I must delete log files manually to login.
Please help me.

Thanks.
Posted
Updated 7-Jun-10 20:27pm
v2

1 solution

Run these two items if you are attempting to flush out transaction log. To restore the MASTER Database though that is tricky. Look Below for Master Restore Process.

If I assume that DB is the name of your Database instance.

DUMP TRANSACTION DB WITH NO_LOG

DBCC SHRINKFILE (DB)

-------------------------------------------

Restore SQL Server 2000 MASTER Database
The MASTER database can only be restored when the database is in single-user mode. To place it in single user mode:
1. Start a command session.
2. To ensure that SQL Server is not running type:
net stop MSSQLServer
This may say that this will also stop another service, in which case allow it to continue. It will also indicate if the service is already stopped.
3. To start SQL Server in single user mode type:
sqlservr -m
If this is not recognised then cd to 'C:\Program Files\Microsoft SQL Server\MSSQL\BINN' and try again.
To restore the MASTER database from the backup use the following script (run in SQL Server Query Analyzer):
use MASTER
go
Restore Database MASTER from Disk =N'D:\Path\MASTER.BAK' with REPLACE, recovery
go
Note: While SQL Server is in single user mode you should still be able to connect from SQL Server Query Analyzer if you connect using the "sa" account.
The above assumes that the file number is 3 for the MASTER database. If unsure on the file number then the list of file numbers can be found by issuing the command:
Restore HeaderOnly from Tape='\\.\Tape0' with nounload
the two fields to look at in the result set are the 'BackupName' and 'Position' which is the file number to be used in the above.
Once the MASTER database has been restored (the restore will have caused the database to be shutdown) start the database by issuing the following command at the command line:
net start MSSQLServer
Remember that the password for the 'sa' account will now be what it was at the time of the original backup.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900