How do I use sp_who2 and the sysprocess table

I need to monitor the jobs that are running in a particular database

when I use sp_who2, I only see the job or sql's that I am running locally from MS SQL Server studio
Also when I use select * from sysprocess, it gives me invalid object name.

How do I use these stored procedure and comand
LVL 1
countrymeisterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brejkCommented:
select * from master.dbo.sysprocesses
0
brejkCommented:
More precisely:

select * from master.dbo.sysprocesses where dbid = db_id('YourDatabaseName')
0
brejkCommented:
But in SQL Server 2005 you may also query like this:

select *
from sys.dm_exec_sessions s
inner join sys.dm_exec_connections c
on s.session_id = c.session_id
cross apply sys.dm_exec_sql_text(c.most_recent_sql_handle) t
where t.dbid = db_id(N'YourDatabaseName')
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

brejkCommented:
Sorry, my last query will not succeed. It will return any records only dbid for stored procedures, not for ad-hoc queries.
0
countrymeisterAuthor Commented:
hi ! brejk

I get 0 rows affected when I run the foll query

select * from master.dbo.sysprocesses where dbid = db_id('exporttrades')
Pretty sure there are jobs running in the database
also tried sp_who2 and it shows nothing, Is this some privileges that I need on the database to view this information
0
brejkCommented:
Try the following:

select db_name(dbid) as db, *
from master.dbo.sysprocesses
order by db

This will return all sessions and they will be sorted by database name (additional first column named db).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
countrymeisterAuthor Commented:
tried it, just shows me my sql run information
0
brejkCommented:
@countrymeister: Could you specify your needs? What do you want to display? And what do you mean writing "jobs"? SQL Agent jobs?
0
countrymeisterAuthor Commented:
brejk

I need to see all the jobs that are running on a database, when i do run sp_who2 i only see my jobs running, not someone else's job which I do know are running
0
countrymeisterAuthor Commented:
brejk, the issue was my userid was not set with the right permissions, I can see the jobs fine now
0
RavinderPanchalCommented:
Hi all , is there any option aor query through which i find that the which DML query execute by whom at what time
0
brejkCommented:
Hi RavinderPanchal,

Run Server Trace to capture query activity. Also you can capture queries run at the moment with sys.dm_exec_requests combined with sys.dm_exec_sql_text.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.