Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
skybvi
Posting Yak Master
193 Posts |
Posted - 2011-12-22 : 15:06:50
|
I am gettting restoring errors(restore job failing) :-Exclusive access could not be obtained beacuse the database is in use.I ran :-alter database dbnameset single_userwith rollback immediatealter database dbname set multi_userThen again tried restoring manually and then again the same error.Regards,SushantDBAVirgin Islands(U.K) |
|
X002548
Not Just a Number
15586 Posts |
|
skybvi
Posting Yak Master
193 Posts |
Posted - 2011-12-22 : 15:44:23
|
If i do restore between the 2 alter statments I get restore error as same as above because database is set as a single user only.Regards,SushantDBAVirgin Islands(U.K) |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2011-12-22 : 15:57:13
|
don't know..that's how I always do itUSE [dba]GOSELECT @@SERVERNAME-- ***-- *** Make Sure the Server Name is -- ***-- Find the Database file to Restore. Make sure it's on the ServerEXEC master..xp_cmdshell 'dir \\servername\instance\path\*.*'-- Look at the internal file informationRESTORE FILELISTONLY FROM DISK = N'\\servername\instance\path\database.BAK' GO-- If the DB Exists, Kick everyone outALTER DATABASE [database] SET SINGLE_USER WITH ROLLBACK IMMEDIATEGO-- RESTORE The database...this will overlay an existing one, OR Create a new one if not in existence-- Get the Logical file names from filelistonlyRESTORE DATABASE [database]FROM DISK = N'\\servername\instance\path\database.BAK' WITH MOVE 'logical data file' TO '\\servername\instance\datafilepath\database.MDF' ,MOVE 'logical log file' TO '\\servername\instance\datafilepath\database_log.LDF' , REPLACEGOALTER DATABASE [database] SET READ_WRITEALTER DATABASE [database] SET MULTI_USERGO Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/ |
|
|
Sachin.Nand
2937 Posts |
Posted - 2011-12-22 : 23:07:28
|
quote: Originally posted by X002548 don't know..that's how I always do itUSE [dba]GOSELECT @@SERVERNAME-- ***-- *** Make Sure the Server Name is -- ***-- Find the Database file to Restore. Make sure it's on the ServerEXEC master..xp_cmdshell 'dir \\servername\instance\path\*.*'-- Look at the internal file informationRESTORE FILELISTONLY FROM DISK = N'\\servername\instance\path\database.BAK' GO-- If the DB Exists, Kick everyone outALTER DATABASE [database] SET SINGLE_USER WITH ROLLBACK IMMEDIATEGO-- RESTORE The database...this will overlay an existing one, OR Create a new one if not in existence-- Get the Logical file names from filelistonlyRESTORE DATABASE [database]FROM DISK = N'\\servername\instance\path\database.BAK' WITH MOVE 'logical data file' TO '\\servername\instance\datafilepath\database.MDF' ,MOVE 'logical log file' TO '\\servername\instance\datafilepath\database_log.LDF' , REPLACEGOALTER DATABASE [database] SET READ_WRITEALTER DATABASE [database] SET MULTI_USERGO Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/
Please dont tell me you have xp_cmdshell enabled on the prod server...PBUH |
|
|
Sachin.Nand
2937 Posts |
Posted - 2011-12-22 : 23:09:22
|
quote: Originally posted by skybvi I am gettting restoring errors(restore job failing) :-Exclusive access could not be obtained beacuse the database is in use.I ran :-alter database dbnameset single_userwith rollback immediatealter database dbname set multi_userThen again tried restoring manually and then again the same error.Regards,SushantDBAVirgin Islands(U.K)
Just restore the database with a new name dbname1 and then drop the old one and rename dbname1 to dbname.PBUH |
|
|
|
|
|
|
|