Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transact SQL connection ID

Status
Not open for further replies.

siliond

Programmer
Aug 7, 2003
13
US
How can I find, with Transact SQL, or something else, the connection id, if this exists, or something unique of the connection.

I want to connect from PHP using mssql_pconnect, and to record with triggers, each modiffication that connection has made to the table.
 
The "connection ID" is called the SPID (Server Process ID) in SQL Server and you can get your current SPID using:

Code:
SELECT @@SPID

Bear in mind though that this is only your current SPID. If you connect again, even from the same app, then you will more than likely get a different SPID. Also, the one you had before will get reused by someone else connecting after you have disconnected.

If you want to record an audit trail of changes then you would be much better off using the user or login of the person making the change. Look up USER_NAME() and SYSTEM_USER in BOL for more info.

--James
 
The SQL Server user is always the same, I made a user php for php connection, so I have to get down to connection ID. I have my own management of users from php, when someone logs into the system I want to store the connection ID and use the same connection, so I can record every change.
The server process ID, is identical for almost all the connections from PHP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top