I’ve got an interesting problem, current we are using NAV5.0, and Sql2005, the problem is these days I found out there are more than 1000 session established by NAV to the DB, however We only have around 45 users. When I use sp_who2 I found out the problem and the Command is awaiting command and status is sleeping. but when I open NAV and found out the current session just 35.
How did you determine that those sessions are established by NAV? It looks to me like there is a user called ‘SQLService’, which would indicate a service that is trying to connect. Is that a NAS instance perhaps, that is not able to log in? Did you check the Windows Event Log?
Hi, the table is too long so some col just missing, actually when run sp_who2 there is a column name ProgramName this column will show you which app connect to the DB. The windows log looks OK. this problem just happened last week.
the strange thing is NAV5 on the SQL server is in a different instance. which is xxx-xxx-1\nav. on that instance when I execuate sp_who2 it looks well, but on xxx-xxx-1 there are too mang login.
Uhh … so you have NAV Logins on instance xxx-xxx-1 even though there is not NAV database installed? To which database are these processes connected then, “master” I suppose? Can’t you simply deny the login to this instance? And all these sessions are inactive, means AWAITING COMMAND … when was the last batch executed?
Well, finding out where those “zombie-sessions” are coming from is one thing, but here a “quickie” how you could get rid of them:
use [master]
go
set statistics io off
set nocount on
go
declare @threshold datetime
set @threshold = dateadd(hour, -6, getdate()) – threshold is 6 hours ago
print 'Killing processes which executed “Last Batch” before ’ + convert(varchar(30), @threshold, 113)
print ‘’
declare @spid int, @last_batch datetime
declare spid_cur cursor for
select [spid], [last_batch] from sysprocesses
where [program_name] = ‘Microsoft Business Solutions-Navision client’ – name depends on NAV version
and [last_batch] <= @threshold
open spid_cur
fetch next from spid_cur into @spid, @last_batch
while @@fetch_status = 0 begin
print 'Killing process ’ + convert(varchar(5), @spid) + ', idle since ’ + convert(varchar(30), @last_batch, 113)
exec ('kill ’ + @spid)
fetch next from spid_cur into @spid, @last_batch
end
close spid_cur
deallocate spid_cur
go
This TSQL script would look for “NAV Client” sessions which have executed the “Last Batch” 6 hours ago; those sessions would be killed. Please change it as you demand - and TEST IT CAREFULLY (e.g. by commenting out the “exec ('kill ’ + @spid)” thing!
This script e.g. could be executed via SQL Agent Job, thus periodically cleaning up the system. USE AT OWN RISK!
Is there a customization that uses ADO commands to connect to the database, but that does not explicitly close the connection at the end of the function? Sometimes those automation type things are picky about housekeeping.