<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlserver.ro/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How-To Articles</title><link>http://sqlserver.ro/forums/19/ShowForum.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Dedicated Administrator Connection (DAC) – a friend in need</title><link>http://sqlserver.ro/forums/thread/91.aspx</link><pubDate>Sat, 16 Sep 2006 10:45:59 GMT</pubDate><guid isPermaLink="false">963f3a18-65dd-4aad-905c-b785cfe1d7c7:91</guid><dc:creator>xmldeveloper</dc:creator><slash:comments>0</slash:comments><comments>http://sqlserver.ro/forums/thread/91.aspx</comments><wfw:commentRss>http://sqlserver.ro/forums/commentrss.aspx?SectionID=19&amp;PostID=91</wfw:commentRss><description>&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;Sometimes computers fail due to hardware or software. This time your database server is not responding. If it’s SQL Server 2005 you still have an alternative to restarting your production server – Dedicated Administrator Connection. This article will give you an idea on what is DAC, how to use it and when to use it.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;&lt;FONT face=Arial size=2&gt;What is DAC ?&lt;/FONT&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;At a first look, Dedicated Administrator Connection or shorter DAC, is just another connection.&amp;nbsp; And that’s true but this connection is very special. It has its own separate memory area, its own scheduler and even its own port. This way by reserving resources, DAC will remain open for business as long as your instance of Database Engine is still started.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;&lt;FONT face=Arial size=2&gt;How to use it ?&lt;/FONT&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;You can initiate a DAC from SQL Server Management Studio or &lt;B&gt;sqlcmd&lt;/B&gt; command-line utility, by prefixing the instance name you will connect to with &lt;B&gt;admin:&lt;/B&gt; prefix. In case of &lt;B&gt;sqlcmd&lt;/B&gt; you have a second option – the &lt;B&gt;–A&lt;/B&gt; switch.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;The following examples are equivalent and demonstrate how to connect to a server named MyServer with Integrated Authentication and using DAC. &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;&lt;FONT face=Arial size=2&gt;Example:&lt;/FONT&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;&lt;SPAN&gt;&lt;FONT face=Arial&gt;sqlcmd –SMyServer -E -A &amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;&lt;SPAN&gt;&lt;FONT face=Arial&gt;sqlcmd –Sadmin:MyServer -E &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face=Arial&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;Another thing I want to mention is that only members of &lt;B&gt;sysadmin&lt;/B&gt; SQL Server role can use DAC and that by default you can use DAC only locally. For remote connections you have to enable them using the &lt;B&gt;remote admin connections&lt;/B&gt; option and &lt;B&gt;sp_configure&lt;/B&gt; stored procedure or Surface Area Configuration utility.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;&lt;FONT face=Arial size=2&gt;Example:&lt;/FONT&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;&lt;SPAN&gt;&lt;FONT face=Arial&gt;sp_configure 'remote admin connections', 1;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;&lt;SPAN&gt;&lt;FONT face=Arial&gt;GO&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;&lt;SPAN&gt;&lt;FONT face=Arial&gt;RECONFIGURE;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;&lt;SPAN&gt;&lt;FONT face=Arial&gt;GO&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face=Arial&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;You can also use DAC with &lt;B&gt;osql &lt;/B&gt;but it’s neither recommended nor supported. &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;To save resources DAC is disabled in SQL Server Express edition but you can turn it on by using a trace flag. Just add "-T7806” to the startup parameters and you are ready to go.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;Maybe you are familiar with this story in which a magical creature (a genie or a goldfish) grants three wishes. The Microsoft SQL Server team grants you just one DAC. So if you use it don’t forget to close it.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;Another thing that makes DAC special is the ability to view and even update the system tables. In 99.99% of cases, it’s absolutely unnecessary to modify directly the system tables. For the others there is DAC. To test this, just run the following example on a standard connection and then on DAC:&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;&lt;FONT face=Arial size=2&gt;Example:&lt;/FONT&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;&lt;SPAN&gt;&lt;FONT face=Arial&gt;SELECT TOP 10 * FROM sys.sysschobjs;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;&lt;SPAN&gt;&lt;FONT face=Arial&gt;GO&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face=Arial&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;You don’t have to know more about the &lt;B&gt;sys.sysschobjs&lt;/B&gt; table other than it is a system table. I will not show you how to modify a system table but I will just mention that you have to start your server in &lt;B&gt;single-user&lt;/B&gt; mode.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;B&gt;&lt;FONT face=Arial size=2&gt;When to use it ?&lt;/FONT&gt;&lt;/B&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;As the title says, DAC is a friend in need but not for &lt;B&gt;every &lt;/B&gt;need. Do not mistake “administrator” for “administrative”. DAC is not meant for administrative tasks. Having a single thread available some administrative commands like BACKUP and RESTORE, or other parallel queries and commands won’t run in DAC. As a rule of thumb if you can’t connect to your server using a standard connection, then try with DAC and proceed with caution. Remember that you’re using DAC because your server is already in trouble and you have the power to make the situation worse by blocking DAC. &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;To avoid that; don’t run resource-intensive queries and limit yourself to basic diagnostic ones.&amp;nbsp;I recommend you the new Dynamic Management Views (views that expose the internal state of the server) such as &lt;B&gt;sys.dm_tran_locks&lt;/B&gt; to get an idea of the current locks, &lt;B&gt;sys.dm_exec_requests&lt;/B&gt; and&lt;B&gt; sys.dm_exec_sessions &lt;/B&gt;that will return information about the current request and sessions. Add &lt;B&gt;KILL&lt;/B&gt; command to this recipe (to help you terminate misbehaving connections) and you have a pretty good toolset at your disposal. &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;If you want to avoid blocking DAC you can run your queries with a LOCK_TIMEOUT value set. Another option is to use READ UNCOMMITTED transaction isolation level. Or even better use both. &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;If there is something that I want you to remember is the fact that you should use DAC only if you need it and do that carefully.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;U&gt;&lt;B&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;Did I mention that DAC won’t timeout? &amp;nbsp;So don’t forget to close it!&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;U&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/U&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal&gt;&lt;SPAN class=bodytext&gt;&lt;FONT face=Arial size=1&gt;Published in Culminis Compass&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;</description></item></channel></rss>