Turn: http://www.cnblogs.com/kerrycode/archive/2010/09/18/1830071.html
SQL Server provides a dedicated administrator Link (DAC ). DAC allows administrators to access the running server to execute diagnostic functions or transact-SQL statements, or to troubleshoot problems on the server, even if the server is locked or runs abnormally.
DAC can only be used on the server by default, but you can use the SQL Server 2005 peripheral application configurator to allow client applications on the remote computer to use DAC, as shown in
You can also use the following sp_configure command to change the database server configuration.
-- 0-indicates that only local connections are allowed to use DAC.
-- 1-specify allow remote connection to use DAC
Sp_configure 'remote admin connections ';
Sp_configure 'remote admin connections', 1;
Go
Reconfigure with override;
Go
You can use SQL Server Management studio or sqlcmd to connect a DAC to a database server. However, note that if you enable SSMs to link to the server like that, an error will be reported (I have been here for a long time)
DAC only supports query windows and does not support object explorer. if you want to use DAC connection in SSMs, you should use a normal connection and use DAC to open the query window. DAC supports only one window. If you have already established a connection, an error is returned. The error 17810 is prompted on msdn, but the 64 errors I encountered on SQL Server 05 are shown in.
The command line interface (sqlcmd) is switched by using a special administrator (-A
), Provides and supports this dedicated administrator connection (DAC ).
The following part of the DAC is from msdn.
Only members of the SQL Server SysAdmin role can use DAC to connect. By default, only clients running on the server can establish connections. Network connection is not allowed unless you use the remote admin connections option through sp_configure. DAC supports encryption and other SQL server security functions. DAC only allows you to switch user context to other management users.
Since DAC is only used to diagnose server problems in rare cases, there are some restrictions on connection:
Microsoft strongly recommends that you use only the following diagnostic and troubleshooting commands, although theoretically you can run any Transact-SQL statement without parallel execution on the DAC:
- Query the dynamic management view (DMV) for basic diagnosis, such as querying sys. dm_tran_locks to learn about the lock status and query sys. dm_ OS _memory_cache_counters checks the cache quality and queries sys. dm_exec_requests and SYS. dm_exec_sessions to learn about active sessions and requests. Avoid using DMV that consumes a large amount of resources (for example, SYS. dm_tran_version_store needs to scan the entire version storage zone, which may lead to a large number of I/O) or using DMV with complex connections. For more information about performance, see the specific DMV documentation.
- Query the directory view.
- Basic DBCC commands, such as DBCC freeproccache, DBCC freesystemcache, DBCC dropcleanbuffers, and DBCC sqlperf. Do not run commands that consume a large amount of resources, such as DBCC checkdb, DBCC dbreindex, or DBCC shrinkdatabase.
- The statement kill <spid>. Based on the SQL server status, the kill command is not always successful. If it fails, the only option is to restart SQL Server. The following are general guiding principles.
- Query
select * from sys.dm_exec_sessions where session_id = <spid>
To verify whether the spid has been terminated. If no row is returned, the session is terminated.
- If the session is still running, run the query
select * from sys.dm_os_tasks where session_id = <spid>
To verify whether a task is assigned to this session. If a task exists, it is likely that the session is being terminated. Note that this operation may last for a long time or fail at all.
- If there are no tasks in the SYS. dm_ OS _tasks associated with this session, but the session still appears in SYS. dm_exec_sessions after the kill command is executed, there is no available working thread. Select a currently running task (listed in SYS. dm_ OS _tasks view)
sessions_id <> NULL
And terminate the associated session to release the working thread. Please note that terminating a single session may not be enough and multiple sessions may need to be terminated.
DAC Port
SQL server listens to DAC on a dedicated TCP/IP Port. The error log contains the port number of the DAC to be listened on. By default, the DAC listener only accepts connections on the local port. For sample code for Activating remote administrator connection, see the remote admin connections option.
After the remote management connection is configured, the DAC listener is enabled immediately without restarting SQL Server.