Getting SPID from SqlConnection

  • Thread starter Thread starter Chetan Raj
  • Start date Start date
C

Chetan Raj

Hi All,

Can we get SPID from the SqlConnection in ADO.NET?

If yes,
how do we get it?
Else
what is the best way to get the SPID of the db calls I am
making from SqlConnection?


Thanks,
Chetan
 
Yes, and the SQL for the SqlCommand you'd use looks like ----

Select spid, rtrim(loginame), rtrim(Program_name), db_name(dbid),
rtrim(status) from master.dbo.sysprocesses where loginame = 'HOMEPC\Sahil
Malik';

Note I said SqlCommand, because that's what you use to execute commands to
the d/b, not SqlConnection, though a SqlCommand will need a valid
SqlConnection object - and it is on that connection object that you will
need proper access rights.

What are you trying to do with SPID though? (Just Curious)

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 
I need SPID for profling commands which take huge time to complete.

I wanted SPID as a property of any SqlClient object, from which i can
know of the SPID whenever the problem occurs.

I don't want to explicitly run a select spid command with all the
commands I run.
 
I need SPID for profling commands which take huge time to complete.

I wanted SPID as a property of any SqlClient object, from which i can
know of the SPID whenever the problem occurs.

I don't want to explicitly run a select spid command with all the
commands I run.

-- Chetan
 
Back
Top