Hi guys,
I am having a database which we refresh every night with same back up where it is used for testing purposes. we will refresh the database thorough job. every time it refreshes it goes to single user mode, I should manually go and change the process using following steps:
1) to execute sp_dboption
sp_dboption 'testdb01', 'single user', 'FALSE';
go
2) to retrieve client session per database
select d.name, d.dbid, spid, login_time, nt_domain, nt_username, loginame
from sysprocesses p inner join sysdatabases d on p.dbid = d.dbid
where d.name = 'testdb01'
go
3) kill the particular session
kill 51
go
4)Now I can ‘remove’ the database from Sinlge user mode.
exec sp_dboption 'testdb01', 'single user', 'FALSE'
go
Is there any way to write a query in which if the session goes to single user mode kill that session and start the restore process again? can you guys help in implementing that code.
thanks,
aravind.