﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / SQL Server 2005 General Discussion  / using sys.dm_exec_sessions , where to find database name/id / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Mon, 20 May 2013 06:40:56 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: using sys.dm_exec_sessions , where to find database name/id</title><link>http://www.sqlservercentral.com/Forums/Topic362235-149-1.aspx</link><description>This query (joining sys.dm_exec_sessions to sys.dm_exec_requests) is functionally different from querying sys.sysprocesses.sys.sysprocesses has the current database context for every session (regardless of whether there are any currently-executing requests). However, joining to sys.dm_exec_requests means that you will only get results for sessions with currently-executing requests.  You'll get fewer roes using sys.dm_exec_requests, and potentially filter out valid results.As of now, I think that the dbid data in sys.sysprocesses is uniquely available in that view, and not available in any other 2012 DMV.</description><pubDate>Mon, 07 Jan 2013 11:42:47 GMT</pubDate><dc:creator>andy.mallon+SQL</dc:creator></item><item><title>RE: using sys.dm_exec_sessions , where to find database name/id</title><link>http://www.sqlservercentral.com/Forums/Topic362235-149-1.aspx</link><description>Yep, that works, thanks.  Did not mean to offend.  The G was a typothanksJIM</description><pubDate>Fri, 22 Jun 2012 07:46:50 GMT</pubDate><dc:creator>james-1023125</dc:creator></item><item><title>RE: using sys.dm_exec_sessions , where to find database name/id</title><link>http://www.sqlservercentral.com/Forums/Topic362235-149-1.aspx</link><description>This should do it[code="sql"]select    es.session_id,    er.database_id,    db_name(er.database_id) AS DBNamefrom    sys.dm_exec_sessions es    inner join sys.dm_exec_requests er on es.session_id = er.session_id;[/code]</description><pubDate>Thu, 21 Jun 2012 15:49:39 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: using sys.dm_exec_sessions , where to find database name/id</title><link>http://www.sqlservercentral.com/Forums/Topic362235-149-1.aspx</link><description>[quote][b]james-1023125 (6/21/2012)[/b][hr]Nope.  sorry but you have sp. in there and no AS for sp.  GTry running it yourself[/quote]Also, didn't see you suggest any alternatives, so keep your snarkiness to yourself please.</description><pubDate>Thu, 21 Jun 2012 15:49:31 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: using sys.dm_exec_sessions , where to find database name/id</title><link>http://www.sqlservercentral.com/Forums/Topic362235-149-1.aspx</link><description>[quote][b]james-1023125 (6/21/2012)[/b][hr]Nope.  sorry but you have sp. in there and no AS for sp.  GTry running it yourself[/quote]Yep, I missed changing a couple of sp aliases.  Sorry.</description><pubDate>Thu, 21 Jun 2012 15:47:00 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: using sys.dm_exec_sessions , where to find database name/id</title><link>http://www.sqlservercentral.com/Forums/Topic362235-149-1.aspx</link><description>Nope.  sorry but you have sp. in there and no AS for sp.  GTry running it yourself</description><pubDate>Thu, 21 Jun 2012 15:40:07 GMT</pubDate><dc:creator>james-1023125</dc:creator></item><item><title>RE: using sys.dm_exec_sessions , where to find database name/id</title><link>http://www.sqlservercentral.com/Forums/Topic362235-149-1.aspx</link><description>How about this:[code="sql"]select    es.session_id,    er.session_id,    er.dbid,    db_name(er.dbid)from    sys.dm_exec_sessions es    inner join sys.dm_exec_requests er on es.session_id = er.session_id;[/code]Edit: Corrected a couple of aliases.</description><pubDate>Thu, 21 Jun 2012 14:51:02 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: using sys.dm_exec_sessions , where to find database name/id</title><link>http://www.sqlservercentral.com/Forums/Topic362235-149-1.aspx</link><description>But the question was, and is how to get it from sys.dm_exec_sessions.  You are joining to the sysprocesses which in deprecated by MS SQL Server 2012 to the sys.dm_ ... viewsread here  http://msdn.microsoft.com/en-us/library/ms179881.aspxJIM</description><pubDate>Thu, 21 Jun 2012 14:43:50 GMT</pubDate><dc:creator>james-1023125</dc:creator></item><item><title>RE: using sys.dm_exec_sessions , where to find database name/id</title><link>http://www.sqlservercentral.com/Forums/Topic362235-149-1.aspx</link><description>Correction: you should use db_name(dbid), not object_name</description><pubDate>Tue, 01 May 2007 11:24:00 GMT</pubDate><dc:creator>Mark Shvarts 1</dc:creator></item><item><title>RE: using sys.dm_exec_sessions , where to find database name/id</title><link>http://www.sqlservercentral.com/Forums/Topic362235-149-1.aspx</link><description>&lt;P&gt;Hello Smith,&lt;/P&gt;&lt;P&gt;Can you check whether this query gives out the desired results you want?&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;P&gt;select&lt;/FONT&gt;&lt;FONT size=2&gt; es&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;.&lt;/FONT&gt;&lt;FONT size=2&gt;session_id&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; sp&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;.&lt;/FONT&gt;&lt;FONT size=2&gt;spid&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; sp&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;.&lt;/FONT&gt;&lt;FONT size=2&gt;dbid&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;,&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#ff00ff size=2&gt;object_name&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;dbid&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;)&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;P&gt;from&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;sys.dm_exec_sessions&lt;/FONT&gt;&lt;FONT size=2&gt; es &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;inner&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;join&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;sys.sysprocesses&lt;/FONT&gt;&lt;FONT size=2&gt; sp &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;on&lt;/FONT&gt;&lt;FONT size=2&gt; es&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;.&lt;/FONT&gt;&lt;FONT size=2&gt;session_id &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;=&lt;/FONT&gt;&lt;FONT size=2&gt; sp&lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;.&lt;/FONT&gt;&lt;FONT size=2&gt;spid&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;Thanks&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt; &lt;/P&gt;&lt;/FONT&gt;</description><pubDate>Tue, 01 May 2007 07:49:00 GMT</pubDate><dc:creator>lucky-80472</dc:creator></item><item><title>using sys.dm_exec_sessions , where to find database name/id</title><link>http://www.sqlservercentral.com/Forums/Topic362235-149-1.aspx</link><description>im using &lt;FONT color=#008000 size=2&gt;sys.dm_exec_sessions &lt;FONT color=#111111&gt;to show me all current sessions ( instead of using sp_who2). the problem is that &lt;FONT size=2&gt;&lt;FONT color=#119911&gt;sys.dm_exec_sessions&lt;/FONT&gt; doesnt have the database name or id. where can i map the spid to , to get the db name?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;</description><pubDate>Tue, 01 May 2007 05:18:00 GMT</pubDate><dc:creator>winston Smith</dc:creator></item></channel></rss>