Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.40 KB | None | 0 0
  1. -- Treat Active Directory as a linked server and then you can query against it.
  2. -- This work is applied against Master as it effects the entire instance.
  3. --
  4. USE [master]
  5. GO
  6. --
  7. -- Clean up if the linked server already exists.
  8. -- ==============================================================================
  9. -- Replace N’AdvWrksDC’ with the name of your Domain Controller
  10. -- throughout this script
  11. -- ==============================================================================
  12. IF EXISTS (SELECT srv.name FROM sys.servers srv WHERE srv.server_id != 0
  13. AND srv.name = N'AdvWrksDC') EXEC master.dbo.sp_dropserver
  14. @server=N'AdvWrksDC', @droplogins='droplogins'
  15. GO
  16. --
  17. -- 'show advanced options' lets us get at the 'Ad Hoc Distributed Queries' option
  18. --
  19. SP_CONFIGURE 'show advanced options',1
  20. GO
  21. reconfigure with override
  22. GO
  23. --
  24. -- 'Ad Hoc Distributed Queries' option - By default, SQL Server does not allow
  25. -- ad hoc distributed queries using OPENROWSET and OPENDATASOURCE. When this is
  26. -- set to 1, SQL Server allows ad hoc access.
  27. --
  28. SP_CONFIGURE 'Ad Hoc Distributed Queries',1
  29. GO
  30. RECONFIGURE WITH OVERRIDE
  31. GO
  32. --
  33. -- Use the sp_addlinkedserver stored procedure, @server is the name of your
  34. -- domain controller
  35. --
  36. EXEC master.dbo.sp_addlinkedserver @server = N'AdvWrksDC', @srvproduct=
  37. N'Active Directory Service Interfaces’, @provider=N'ADSDSOObject',
  38. @datasrc=N'adsdatasource'
  39. --
  40. -- ==============================================================================
  41. -- You need a domain login which has access to Active Directory
  42. -- information @rmtuser and @rmtpassword identify this user
  43. -- ==============================================================================
  44. --
  45. EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'AdvWrksDC', @useself=N'False',
  46. @locallogin=NULL, @rmtuser=N'adventure-works\Administrator',
  47. @rmtpassword='******'
  48. GO
  49. -- Treat Active Directory as a linked server and then you can query against it.
  50. -- This work is applied against Master as it effects the entire instance.
  51. --
  52. USE [master]
  53. GO
  54. --
  55. -- Clean up if the linked server already exists.
  56. -- ==============================================================================
  57. -- Replace N’AdvWrksDC’ with the name of your Domain Controller
  58. -- throughout this script
  59. -- ==============================================================================
  60. IF EXISTS (SELECT srv.name FROM sys.servers srv WHERE srv.server_id != 0
  61. AND srv.name = N'AdvWrksDC') EXEC master.dbo.sp_dropserver
  62. @server=N'AdvWrksDC', @droplogins='droplogins'
  63. GO
  64. --
  65. -- 'show advanced options' lets us get at the 'Ad Hoc Distributed Queries' option
  66. --
  67. SP_CONFIGURE 'show advanced options',1
  68. GO
  69. reconfigure with override
  70. GO
  71. --
  72. -- 'Ad Hoc Distributed Queries' option - By default, SQL Server does not allow
  73. -- ad hoc distributed queries using OPENROWSET and OPENDATASOURCE. When this is
  74. -- set to 1, SQL Server allows ad hoc access.
  75. --
  76. SP_CONFIGURE 'Ad Hoc Distributed Queries',1
  77. GO
  78. RECONFIGURE WITH OVERRIDE
  79. GO
  80. --
  81. -- Use the sp_addlinkedserver stored procedure, @server is the name of your
  82. -- domain controller
  83. --
  84. EXEC master.dbo.sp_addlinkedserver @server = N'AdvWrksDC', @srvproduct=
  85. N'Active Directory Service Interfaces’, @provider=N'ADSDSOObject',
  86. @datasrc=N'adsdatasource'
  87. --
  88. -- ==============================================================================
  89. -- You need a domain login which has access to Active Directory
  90. -- information @rmtuser and @rmtpassword identify this user
  91. -- ==============================================================================
  92. --
  93. EXEC master.dbo.sp_addlinkedsrvlogin @rmtsrvname=N'AdvWrksDC', @useself=N'False',
  94. @locallogin=NULL, @rmtuser=N'adventure-works\Administrator',
  95. @rmtpassword='******'
  96. GO
  97. --
  98. -- 'collation compatible' false indicates that AD might not have the collation
  99. -- as SQLServer Instance
  100. --
  101. EXEC master.dbo.sp_serveroption @server=N'AdvWrksDC',
  102. @optname=N'collation compatible’, @optvalue=N'false'
  103. GO
  104. --
  105. -- 'data access' true Enables a linked server for distributed query access
  106. EXEC master.dbo.sp_serveroption @server=N'AdvWrksDC', @optname=N'data access',
  107. @optvalue=N'true'
  108. GO
  109. --
  110. -- 'dist' false indicates this linked server is not a Distributor
  111. EXEC master.dbo.sp_serveroption @server=N'AdvWrksDC', @optname=N'dist',
  112. @optvalue=N'false'
  113. GO
  114. --
  115. -- 'pub' false indicates this linked server is not a Publisher.
  116. EXEC master.dbo.sp_serveroption @server=N'AdvWrksDC', @optname=N'pub',
  117. @optvalue=N'false'
  118. GO
  119. --
  120. -- 'rpc' false disables RPC from the given server.
  121. EXEC master.dbo.sp_serveroption @server=N'AdvWrksDC', @optname=N'rpc',
  122. @optvalue=N'false'
  123. GO
  124. --
  125. -- 'rpc out' false disables RPC to the given server.
  126. EXEC master.dbo.sp_serveroption @server=N'AdvWrksDC', @optname=N'rpc out',
  127. @optvalue=N'false'
  128. GO
  129. --
  130. -- 'sub' false indicates that this linked server is not a Subscriber
  131. EXEC master.dbo.sp_serveroption @server=N'AdvWrksDC', @optname=N'sub',
  132. @optvalue=N'false'
  133. GO
  134. --
  135. -- 'connect timeout' = 0 indicates to use the default for a connection timeout
  136. EXEC master.dbo.sp_serveroption @server=N'AdvWrksDC', @optname=N'connect timeout',
  137. @optvalue=N'0'
  138. GO
  139. --
  140. -- 'collation name' null Specifies the name of the collation used by the remote
  141. -- data source if use remote collation is true and the data source is not a SQL
  142. -- Server data source. The name must be one of the collations supported by SQL
  143. -- Server.
  144. EXEC master.dbo.sp_serveroption @server=N'AdvWrksDC', @optname=N'collation name',
  145. @optvalue=null
  146. GO
  147. --
  148. -- 'lazy schema validation' false Determines whether the schema of remote tables
  149. -- will be checked.
  150. EXEC master.dbo.sp_serveroption @server=N'AdvWrksDC',
  151. @optname=N'lazy schema validation’, @optvalue=N'false'
  152. GO
  153. --
  154. -- 'query timeout' = 0 indicates to use the default for a queryeout
  155. EXEC master.dbo.sp_serveroption @server=N'AdvWrksDC', @optname=N'query timeout',
  156. @optvalue=N'0'
  157. GO
  158. --
  159. -- 'use remote collation' true indicates the collation of the remove server will
  160. -- be used
  161. EXEC master.dbo.sp_serveroption @server=N'AdvWrksDC', @optname=N'use remote collation’, @optvalue=N'true'
  162. GO
  163. --
  164. -- 'remote proc transaction promotion' true Use this option to protect the actions
  165. -- of a server-to-server procedure through a Microsoft Distributed Transaction
  166. -- Coordinator (MS DTC) transaction. When this option is TRUE (or ON) calling a
  167. -- remote stored procedure starts a distributed transaction and enlists the
  168. -- transaction with MS DTC.
  169. EXEC master.dbo.sp_serveroption @server=N'AdvWrksDC',
  170. @optname=N'remote proc transaction promotion', @optvalue=N'true'
  171. GO
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement