Question : Is there a cmd to see active sessions in SQL 2005?

On occasion I need to overwrite/restore a database, I have a script to do that for me.  Generally I would logon to the server console check SQL Ent Mgr to ensure no one is using the DB that I want to restore and then run my script to restore the DB.  That process work fine.  What I want to do is access the SQL 2005 server remotely using ssh.  Check to ensure no one is in the database and then run my script.

How can I check to make sure no one is using the database (using ssh cmd line) before I restore it?

Answer : Is there a cmd to see active sessions in SQL 2005?

better way to do it...this will kill them for you.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
DECLARE  tempcursor
CURSOR
READ_ONLY
FOR 
	select spid From master..sysprocesses
	where dbid = (select database_id from sys.databases where name = 'yourdbname')
 
DECLARE @name int
OPEN tempcursor
 
FETCH NEXT FROM tempcursor INTO @name
WHILE (@@fetch_status <> -1)
BEGIN
	exec('kill ' + @name)
 
	FETCH NEXT FROM tempcursor INTO @name
END
 
CLOSE tempcursor
DEALLOCATE tempcursor
Random Solutions  
 
programming4us programming4us