Using a Dedicated Administrator Connection

SQL Server 2005 provides a special diagnostic connection for administrators when standard connections to the server are not possible.

By default, the connection is only allowed from a client running on the server. Network connections are not permitted unless they are configured by using the SQL Server Surface Area Configuration tool or the sp_configure stored procedure with the remote admin connections option.

Only members of the SQL Server sysadmin role can connect using the DAC.

The DAC is available and supported through the sqlcmd command-prompt utility using a special administrator switch (-A). You can also initiate a DAC from a SQL Server Management Studio Query Editor by connecting to admin:<instance_name>.

Because the DAC exists solely for diagnosing server problems in rare circumstances, there are some restrictions on the connection:

·         To guarantee that there are resources available for the connection, only one DAC is allowed per instance of SQL Server. If a DAC connection is already active, any new request to connect through the DAC is denied with error 17810.

·         To conserve resources, SQL Server 2005 Express Edition does not listen on the DAC port unless started with a trace flag 7806.

·         The DAC initially attempts to connect to the default database associated with the login. After it is successfully connected, you can connect to the master database. If the default database is offline or otherwise not available, the connection will return error 4060. However, it will succeed if you override the default database to connect to the master database instead using the following command:

sqlcmd –A –d master

We recommend that you connect to the master database with the DAC because master is guaranteed to be available if the instance of the Database Engine is started.

·         SQL Server prohibits running parallel queries or commands with the DAC. For example, error 3637 is generated if you execute either of the following statements with the DAC:

o    RESTORE

o    BACKUP

·         Only limited resources are guaranteed to be available with the DAC. Do not use the DAC to run resource-intensive queries (for example. a complex join on large table) or queries that may block.

Although you can theoretically run any Transact-SQL statement that does not have to execute in parallel on the DAC, we strongly recommend that you restrict usage to the following diagnostic and troubleshooting commands:

·         Querying dynamic management views for basic diagnostics such as sys.dm_tran_locks for the locking status, sys.dm_os_memory_cache_counters to check the health of caches, and sys.dm_exec_requests and sys.dm_exec_sessions for active sessions and requests. Avoid dynamic management views that are resource intensive (for example, sys.dm_tran_version_store scans the full version store and can cause extensive I/O) or that use complex joins. For information about performance implications, see the documentation for the specific dynamic management view.

·         Querying catalog views.

·         Basic DBCC commands such as DBCC FREEPROCCACHE, DBCC FREESYSTEMCACHE, DBCC DROPCLEANBUFFERS, and DBCC SQLPERF. Do not run resource-intensive commands such as DBCC CHECKDB, DBCC DBREINDEX, or DBCC SHRINKDATABASE.

·         Transact-SQL KILL <spid> command. Depending on the state of SQL Server, the KILL command might not always succeed; then the only option may be to restart SQL Server. The following are some general guidelines:

o    Verify that the SPID was actually killed by querying SELECT * FROM sys.dm_exec_sessions WHERE session_id = <spid>. If it returns no rows, it means the session was killed.

o    If the session is still there, verify whether there are tasks assigned to this session by running the query SELECT * FROM sys.dm_os_tasks WHERE session_id = <spid>. If you see the task there, most likely your session is currently being killed. Note that this may take considerable amount of time and may not succeed at all.

o    If there are no tasks in the sys.dm_os_tasks associated with this session, but the session remains in sys.dm_exec_sessions after executing the KILL command, it means that you do not have a worker available. Select one of the currently running tasks (a task listed in the sys.dm_os_tasks view with a sessions_id <> NULL), and kill the session associated with it to free up the worker. Note that it may not be enough to kill a single session: you may have to kill multiple ones.

For example, an administrator notices that server URAN123 is not responding and wants to diagnose the problem. To do this, the user activates the sqlcmd command prompt utility and connects to server URAN123 using -A to indicate the DAC.

sqlcmd -S URAN123 -U sa -P <xxx> –A

The administrator can now execute queries to diagnose the problem and possibly terminate the unresponsive sessions.

Making DAC from Sql Server Management Studio :

1.     In SQL Server Management Studio, with no other DACs open, on the toolbar, click Database Engine Query.

2.     In the Connect to Database Engine dialog box, in the Server name box, type ADMIN: followed by the name of the server instance. For example, to connect to a server instance named ACCT\PAYABLE, type ADMIN:ACCT\PAYABLE.

3.     Complete the Authentication section, providing credentials for a member of the sysadmin group, and then click Connect.

The connection is made.