The following function returns a table of logged in users so I can
programatically limit the number of connections per user to one. In some
instances the program drops the connection without SQL server realizing the
user has logged out, IE loss of internet connection, system crash etc.,
which leaves a row in the sysprocesses table. If I created a delete function
to delete the row from sysprocesses, are there any other tables which I
would need to update/ delete from? Is there an easier way to get around this
(some sort of sp_logOutUser) ?

Thanx in advance,

Aaron

CREATE FUNCTION fn_LoggedIN ( )
RETURNS TABLE
AS
RETURN
SELECT
sp.spid
,convert(sysname, rtrim(sp.loginame))
as loginname
,sp.status
,sp.hostname
,sp.program_name
,sp.cmd
,sp.cpu
,sp.physical_io
,sp.blocked
,sp.dbid
,sp.spid as 'spid_sort'
, substring( convert(varchar,sp.last_batch,111) ,6 ,5 ) + ' '
+ substring( convert(varchar,sp.last_batch,113) ,13 ,8 )
as 'last_batch_char'
FROM master.dbo.sysprocesses as sp (nolock)
WHERE sp.status <> 'background'
AND rtrim(sp.loginame) <> 'sa'
AND IS_SRVROLEMEMBER('sysadmin', rtrim(sp.loginame)) <> 1