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.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Log shipping error

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 dbname
set single_user
with rollback immediate

alter database dbname set multi_user

Then again tried restoring manually and then again the same error.


Regards,
Sushant
DBA
Virgin Islands(U.K)

X002548
Not Just a Number

15586 Posts

Posted - 2011-12-22 : 15:19:58
where's the RESTORE?

USE [master]
GO

alter database dbname set single_user with rollback immediate

RESTORE....

alter database dbname set multi_user


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

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,
Sushant
DBA
Virgin Islands(U.K)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-12-22 : 15:57:13
don't know..that's how I always do it


USE [dba]
GO

SELECT @@SERVERNAME

-- ***
-- *** Make Sure the Server Name is
-- ***


-- Find the Database file to Restore. Make sure it's on the Server
EXEC master..xp_cmdshell 'dir \\servername\instance\path\*.*'


-- Look at the internal file information
RESTORE FILELISTONLY
FROM DISK = N'\\servername\instance\path\database.BAK'
GO

-- If the DB Exists, Kick everyone out

ALTER DATABASE [database] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO

-- RESTORE The database...this will overlay an existing one, OR Create a new one if not in existence
-- Get the Logical file names from filelistonly

RESTORE 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'
, REPLACE
GO

ALTER DATABASE [database] SET READ_WRITE
ALTER DATABASE [database] SET MULTI_USER
GO



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

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 it


USE [dba]
GO

SELECT @@SERVERNAME

-- ***
-- *** Make Sure the Server Name is
-- ***


-- Find the Database file to Restore. Make sure it's on the Server
EXEC master..xp_cmdshell 'dir \\servername\instance\path\*.*'


-- Look at the internal file information
RESTORE FILELISTONLY
FROM DISK = N'\\servername\instance\path\database.BAK'
GO

-- If the DB Exists, Kick everyone out

ALTER DATABASE [database] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO

-- RESTORE The database...this will overlay an existing one, OR Create a new one if not in existence
-- Get the Logical file names from filelistonly

RESTORE 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'
, REPLACE
GO

ALTER DATABASE [database] SET READ_WRITE
ALTER DATABASE [database] SET MULTI_USER
GO



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/






Please dont tell me you have xp_cmdshell enabled on the prod server...

PBUH

Go to Top of Page

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 dbname
set single_user
with rollback immediate

alter database dbname set multi_user

Then again tried restoring manually and then again the same error.


Regards,
Sushant
DBA
Virgin Islands(U.K)



Just restore the database with a new name dbname1 and then drop the old one and rename dbname1 to dbname.

PBUH

Go to Top of Page
   

- Advertisement -