There's not really a reliable way to pin sessions to a specific database (
sysprocesses has this, but it relies on an active query's database context, and
authenticating_database_id, but this relies on the connection string, login's default database, etc).
That said, this seems to meet all of your other requirements, attempting to kill all sessions using
app_name, connecting as
login_name, and who haven't issued a request in the last 5 hours:
DECLARE @sql NVARCHAR(MAX) = N'';
SELECT @sql += N'KILL ' + CONVERT(VARCHAR(11), session_id) + N';'
WHERE [program_name] = N'app_name'
AND login_name = N'login_name'
AND last_request_start_time < DATEADD(HOUR, -5, SYSDATETIME());
EXEC sys.sp_executesql @sql;
If all the app does is call that one stored procedure and never does anything else at all, you could perhaps look at
DBCC INPUTBUFFER for each spid, but that becomes very tedious very quickly.