<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dm_tran_locks &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/dm_tran_locks/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Sun, 07 Jan 2018 19:01:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>SQL Server: Find total number of Sessions of a Database</title>
		<link>https://www.dbrnd.com/2018/01/sql-server-find-total-number-of-sessions-of-a-database/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 24 Jan 2018 16:16:11 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[dm_tran_locks]]></category>
		<category><![CDATA[Session]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[user]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6982</guid>

					<description><![CDATA[In this post, I am sharing a script for getting a total number of connected sessions of a SQL Server Database. There are multiple ways for getting the information of connected users, but I am sharing one of the handy DBA scripts which they can use in their day to day work. Check the below [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-find-total-number-of-sessions-of-a-database%2F&amp;linkname=SQL%20Server%3A%20Find%20total%20number%20of%20Sessions%20of%20a%20Database" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-find-total-number-of-sessions-of-a-database%2F&amp;linkname=SQL%20Server%3A%20Find%20total%20number%20of%20Sessions%20of%20a%20Database" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-find-total-number-of-sessions-of-a-database%2F&amp;linkname=SQL%20Server%3A%20Find%20total%20number%20of%20Sessions%20of%20a%20Database" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-find-total-number-of-sessions-of-a-database%2F&amp;linkname=SQL%20Server%3A%20Find%20total%20number%20of%20Sessions%20of%20a%20Database" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-find-total-number-of-sessions-of-a-database%2F&amp;linkname=SQL%20Server%3A%20Find%20total%20number%20of%20Sessions%20of%20a%20Database" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-find-total-number-of-sessions-of-a-database%2F&amp;linkname=SQL%20Server%3A%20Find%20total%20number%20of%20Sessions%20of%20a%20Database" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-find-total-number-of-sessions-of-a-database%2F&#038;title=SQL%20Server%3A%20Find%20total%20number%20of%20Sessions%20of%20a%20Database" data-a2a-url="https://www.dbrnd.com/2018/01/sql-server-find-total-number-of-sessions-of-a-database/" data-a2a-title="SQL Server: Find total number of Sessions of a Database"></a></p><p>In this post, I am sharing a script for getting a total number of connected sessions of a SQL Server Database. </p>
<p>There are multiple ways for getting the information of connected users, but I am sharing one of the handy DBA scripts which they can use in their day to day work. </p>
<p><strong>Check the below script: </strong></p>
<pre class="crayon-plain-tag">select
       db_name (resource_database_id) as DatabaseName
       ,count (*) as TotalSessions
from sys.dm_tran_locks
where resource_type = 'DATABASE'
	and db_name (resource_database_id) = 'Database_Name'
group by db_name (resource_database_id)
order by db_name (resource_database_id)</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: When records lock, use %%lockres%% to find the page information of records</title>
		<link>https://www.dbrnd.com/2017/03/sql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 04 Mar 2017 16:16:35 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[%%lockres%%]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[data page]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[DeadLock]]></category>
		<category><![CDATA[dm_tran_locks]]></category>
		<category><![CDATA[lock]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4689</guid>

					<description><![CDATA[I shared a couple of articles on SQL Server database locking and how to detect a deadlock. Please access few of them. Different ways to detect a deadlock What happens after the Deadlock? I recently found an undocumented function %%lockres%% which we can use to locate the page information of records especially for those records [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fsql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records%2F&amp;linkname=SQL%20Server%3A%20When%20records%20lock%2C%20use%20%25%25lockres%25%25%20to%20find%20the%20page%20information%20of%20records" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fsql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records%2F&amp;linkname=SQL%20Server%3A%20When%20records%20lock%2C%20use%20%25%25lockres%25%25%20to%20find%20the%20page%20information%20of%20records" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fsql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records%2F&amp;linkname=SQL%20Server%3A%20When%20records%20lock%2C%20use%20%25%25lockres%25%25%20to%20find%20the%20page%20information%20of%20records" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fsql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records%2F&amp;linkname=SQL%20Server%3A%20When%20records%20lock%2C%20use%20%25%25lockres%25%25%20to%20find%20the%20page%20information%20of%20records" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fsql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records%2F&amp;linkname=SQL%20Server%3A%20When%20records%20lock%2C%20use%20%25%25lockres%25%25%20to%20find%20the%20page%20information%20of%20records" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fsql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records%2F&amp;linkname=SQL%20Server%3A%20When%20records%20lock%2C%20use%20%25%25lockres%25%25%20to%20find%20the%20page%20information%20of%20records" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fsql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records%2F&#038;title=SQL%20Server%3A%20When%20records%20lock%2C%20use%20%25%25lockres%25%25%20to%20find%20the%20page%20information%20of%20records" data-a2a-url="https://www.dbrnd.com/2017/03/sql-server-when-records-lock-use-lockres-to-find-the-page-information-of-records/" data-a2a-title="SQL Server: When records lock, use %%lockres%% to find the page information of records"></a></p><p>I shared a couple of articles on SQL Server database locking and how to detect a deadlock. Please access few of them.</p>
<p><strong><a href="https://www.dbrnd.com/2016/04/sql-server-8-different-ways-to-detect-a-deadlock-in-a-database/" target="_blank">Different ways to detect a deadlock</a></strong><br />
<a href="https://www.dbrnd.com/2016/04/sql-server-what-happens-after-the-deadlock-arise/" target="_blank"><strong>What happens after the Deadlock?</strong></a></p>
<blockquote><p>I recently found an undocumented function <strong>%%lockres%%</strong> which we can use to locate the page information of records especially for those records which hold a Lock.</p></blockquote>
<blockquote><p>It returns a hash value same as like column &#8220;resource_description&#8221; of table sys.dm_tran_locks, but the good thing is you can use it in your SELECT statement and can correlate the column resource_description of table sys.dm_tran_locks.</p></blockquote>
<p>By this way, you can get the exact record, and it&#8217;s page info which currently held by a Lock.</p>
<p>Let me demonstrate this,<br />
<strong>Prerequisites:</strong><br />
Use below article and generate a sample deadlock situation in your database server.</p>
<blockquote class="wp-embedded-content" data-secret="FLnip7cgnO"><p><a href="https://www.dbrnd.com/2016/04/sql-server-t-sql-script-to-generate-a-deadlock-in-a-database/">SQL Server: T-SQL script to generate a DeadLock in a Database</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/04/sql-server-t-sql-script-to-generate-a-deadlock-in-a-database/embed/#?secret=FLnip7cgnO" data-secret="FLnip7cgnO" width="600" height="338" title="&#8220;SQL Server: T-SQL script to generate a DeadLock in a Database&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>Check the result of below query and note down the result of column &#8220;resource_description&#8221;:</strong></p><pre class="crayon-plain-tag">select *from sys.dm_tran_locks</pre><p>
<img fetchpriority="high" decoding="async" class="alignnone wp-image-4696 size-full" title="SQL Server Deadlock Result" src="https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockResult.png" alt="SQL Server Deadlock Result" width="628" height="272" srcset="https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockResult.png 628w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockResult-300x130.png 300w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockResult-150x65.png 150w" sizes="(max-width: 628px) 100vw, 628px" /></p>
<p><strong>Use %%lockres%% and SELECT both the tables:</strong><br />
You can easily correlate the result of sys.dm_tran_locks column resource_description and the result of %%lockres%%. You can find an exact record which held by a Lock.</p><pre class="crayon-plain-tag">SELECT %%lockres%% AS RecordPageInfo,* 
FROM tbl_SampleTable_A

SELECT %%lockres%% AS RecordPageInfo,* 
FROM tbl_SampleTable_B</pre><p>
<img decoding="async" class="alignnone wp-image-4695 size-full" title="SQL Server Deadlock Record Page Info" src="https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockRecordPageInfo.png" alt="SQL Server Deadlock Record Page Info" width="328" height="643" srcset="https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockRecordPageInfo.png 328w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockRecordPageInfo-153x300.png 153w, https://www.dbrnd.com/wp-content/uploads/2017/02/SQLServerDeadlockRecordPageInfo-150x294.png 150w" sizes="(max-width: 328px) 100vw, 328px" /></p>
<p>After this exercise, Please COMMIT all your open transactions.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
