Wednesday, March 21, 2012

Restoring of database using SQL-DMO part 2

Hi its me again, I posted a message some time ago concerning restoring of database.

http://www.dbforums.com/showthread.php?postid=3582736#post3582736

My restore module basically restores a backup of a database file.

I found that when I integrate my restore module with a login module, I am getting the same exclusive access error again. I also found out that the connection created for authenticating the user, remains sleeping even after it is closed, which in effect prevents my restore module to get exclusive access.

What am I doing wrong? Any ideas appreciated, thanks for reading!Run This before you restore database statement:
declare @.l_spid varchar(4)
,@.l_hostname varchar(20)

declare kill_cursor scroll cursor
for
select convert(varchar(4), spid), hostname from master..sysprocesses with (nolock)
where db_name(dbid) = 'Your Database Name'

open kill_cursor
select @.@.cursor_rows

fetch next from kill_cursor into
@.l_spid
,@.l_hostname
while (@.@.fetch_status = 0 )
begin
select @.l_hostname Killed
exec ( 'kill ' + @.l_spid)
fetch next from kill_cursor into
@.l_spid
,@.l_hostname
end
close kill_cursor
deallocate kill_cursor

YOUR RESTORE DATABASE STATEMENT|||Thanks suresh. I will try that.sql

No comments:

Post a Comment