Guest User

Untitled

a guest
Mar 4th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. SELECT * FROM OpenQuery(
  2. ADSI,
  3. 'SELECT displayName, title, department, employeeID, userAccountControl
  4. FROM ''LDAP://dc=testdomain''
  5. WHERE objectCategory = ''Person'' AND
  6. objectClass = ''user'' AND
  7. userAccountControl=512')
  8.  
  9. Msg 7321, Level 16, State 2, Line 1
  10. An error occured while preparing the query "SELECT displayName, title, department, employeeID, userAccountControl
  11. FROM 'LDAP://dc=testdomain'
  12. WHERE objectCategory = 'Person' AND
  13. objectClass = 'user' AND
  14. userAccountControl=512" for execution against OLE DB provider "ADsDSOObject" for linked server "ADSI".
  15.  
  16. SQL Server 11.0.5058
  17. Linked Server: ADSI
  18. Provider: OLE DB Provider for Microsoft Directory Services
  19. Product name: Active Directory Services 2.5
  20. Data source: adsdatasource
  21. Provider string: ADsDSOObject
  22.  
  23. Be made using the login's current security context
  24.  
  25. Ole DB Provider Options:
  26. Allow in process
  27.  
  28. Failed to retreive data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)
  29.  
  30. Additional information:
  31. An exception occured while executing a Transact-SQL statement or batch.
  32. (Microsoft.SqlServer.ConnectionInfo)
  33. Cannot obtain the required interface ("IID_IDBSchemaRowset") from OLE DB provider "ADsDSOObject"
  34. for linked server "ADSI". (Microsoft SQL Server, Error: 7301)
  35.  
  36. 'References: Microsoft ActiveX Data Objects 2.8 Library
  37. Public Sub testADSI()
  38. On Error Resume Next
  39.  
  40. Dim cn As ADODB.Connection
  41. Dim cmd As ADODB.Command
  42. Dim rs as ADODB.Recordset
  43. Dim MySql as String
  44. Dim n as Integer
  45.  
  46. Set cn = New ADODB.Connection
  47. Set cmd = New ADODB.Command
  48. Set rs = New ADODB.Recordset
  49.  
  50. cn.Provider = "ADsDSOObject"
  51. cn.Open "Active Directory Provider"
  52.  
  53. Set cmd.ActiveConnection = cn
  54.  
  55. cmd.Properties("Page Size")= 1000
  56.  
  57. MySql = "SELECT displayName, title, department, employeedID, userAccountControl " & _
  58. "FROM 'LDAP://dc=testdomain' " _ &
  59. "WHERE objectCategory = 'Person' AND " & _
  60. "objectClass = 'user' AND " & _
  61. "userAccountControl=512"
  62.  
  63. rs.Open MySql, cn, 1
  64.  
  65. If rs.RecordCount > 0 Then
  66. MsgBox "Sucess! " & rs.RecordCount & " records found!"
  67. Else
  68. MsgBox "No records"
  69. End IF
  70. End Sub
Add Comment
Please, Sign In to add comment