设为首页 收藏本站
查看: 2101|回复: 0

[经验分享] SQL Server专用管理员连接(Dedicated Admin Connection(DAC))

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-9-6 08:47:47 | 显示全部楼层 |阅读模式
SQL Server专用管理员连接(Dedicated Admin Connection(DAC))

只有 SQL Server sysadmin 角色的成员可以使用 DAC 连接。默认情况下,只能从服务器上运行的客户端建立连接。

打开SSMS,在“Connect to Server”窗口,选择“Cancel”,然后选择File菜单,下拉菜单选择“New”、“Database Engine Query”。
wKiom1fNNI_SxP2iAABWVlqNeuk383.jpg
输入“admin:.”,点击“Connect”。
wKioL1fNNJCxmq-CAABafoX8NIo342.jpg
默认不允许使用网络连接DAC,需要通过sp_configure配置“remote admin connections”选项。

先来看看配置的默认值:
1
SELECT * FROM sys.configurations where name = 'remote admin connections'



或者
1
sp_configure 'remote admin connections'



wKioL1fNNJGBxzydAAARvsqnHNc781.jpg
Value默认为0,指明仅允许本地连接使用 DAC。Maximum为1,表明只运行一个远程管理连接。

1
2
3
4
5
--启用远程DAC连接
sp_configure 'remote admin connections', 1;
GO
RECONFIGURE;
GO



输出:
Configuration option 'remote admin connections' changed from 0 to 1. Run the RECONFIGURE statement to install.

然后开启SQL Server Browser服务,防火墙允许TCP 1434端口的访问。
我们通过另一台服务器上的SSMS建立DAC查询连接,选择File菜单,下拉菜单选择“New”、“Database Engine Query”。
wKiom1fNNJKhrFCxAABa4wNF93k039.jpg
输入域名或IP即可。

DAC在SSMS连接时,只能通过建立查询窗口的方式打开。当SQL Server因系统资源不足,或其它异常导致无法建立数据库连接时, 可以使用系统预留的DAC连接到数据库,进行一些问题诊断和故障排除。DAC只能使用有限的资源。请勿使用DAC运行需要消耗大量资源的查询,否则可能发生严重的阻塞。

另一种打开方式是在命令行界面通过SqlCMD使用特殊的管理员开关(-A),提供对DAC的支持。

本地DAC连接:
wKioL1fNNJPx585lAAAhn4garjs002.jpg
远程DAC连接:
wKiom1fNNJPRSVA_AAAjDziNl68865.jpg

《SQL Server 2012 Internals》有这么一段话:

SQL Server maintains a set of tables that store information about all objects, data types, constraints,confguration options, and resources available to SQL Server. In SQL Server 2012, these tables are called the system base tables. Some of the system base tables exist only in the master database and contain system-wide information; others exist in every database (including master) and contain information about the objects and resources belonging to that particular database. Beginning with SQL Server 2005, the system base tables aren’t always visible by default, in master or any other database. You won’t see them when you expand the tables node in the Object Explorer in SQL Server Management Studio, and unless you are a system administrator, you won’t see them when you execute the sp_help system procedure. If you log on as a system administrator and select from the catalog view called sys.objects (discussed shortly), you can see the names of all the system tables. For example, the following query returns 74 rows of output on my SQL Server 2012 instance:

USE master;
SELECT name FROM sys.objects
WHERE type_desc = 'SYSTEM_TABLE';

But even as a system administrator, if you try to select data from one of the tables returned by the preceding query, you get a 208 error, indicating that the object name is invalid. The only way to see the data in the system base tables is to make a connection using the dedicated administrator connection (DAC), which Chapter 2, “The SQLOS,” explains in the section titled “The scheduler.” Keep in mind that the system base tables are used for internal purposes only within the Database Engine and aren’t intended for general use. They are subject to change, and compatibility isn’t guaranteed. In SQL Server 2012, three types of system metadata objects are intended for general use: Compatibility Views, Catalog Views, and Dynamic Management Objects.


例如,在SSMS中连接普通查询连接,输入:
1
SELECT * FROM sys.sysrmtlgns;



输出:
Msg 208, Level 16, State 1, Line 1
Invalid object name 'sys.sysrmtlgns'.

建立DAC连接,输入:
1
2
3
SELECT net_transport,auth_scheme,client_net_address FROM sys.dm_exec_connections WHERE session_id=@@spid;
SELECT * FROM sys.sysrmtlgns;
SELECT * FROM sys.syslnklgns;



wKioL1fNNJST0oAGAABoberZi8E493.jpg


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-268266-1-1.html 上篇帖子: SqlServer 2008r2备份到共享磁盘 下篇帖子: 【T-SQL 密技】之【化整為零讓程式從31分26秒,縮到2秒】 管理员
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表