我不确定我在这里做错了什么。
我正在尝试从 Active Directory 中检索一些值并将它们插入到我们的 sql server 数据库中。
我在第 23 行“提供者:未指定的错误”上不断收到错误消息
这是第 23 行 --> 设置 adoRecordset = adoCommand.Execute
以下是我正在使用的代码,谢谢:
'==============
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
strFilter = "(&(objectCategory=person)(objectClass=user))"
'strFilter = "(&(objectClass=computer)(cn=" & strComputer & "))"
' Comma delimited list of attribute values to retrieve.
'strAttributes = "sAMAccountName,cn"
strAttributes = "employeeID,name,givenName,sname"
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
' Run the query.
Set adoRecordset = adoCommand.Execute **<--Error pointing to this line**
' ******** SET UP DB CONNECTION **********
Set dbConn = createobject("ADODB.Connection")
dbConn.ConnectionString = "driver=Sql Server;server=serverName;uid=myuser;pwd=mypwd;database=myDB"
dbConn.Open
' *****************************************
strDetails = ""
' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values and display.
strEmpID = adoRecordset.Fields("employeeID").Value
strName = adoRecordset.Fields("name").Value
strfname = adoRecordset.Fields("givenName").Value
strlname = adoRecordset.Fields("sname").Value
' ******* INSERT INTO DB *************
dbConn.Execute "INSERT INTO myTable Values('" & strEmpID & "','" & strName & "','" & strfname & "','" & strlname & "')"
' ************************************
' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop
' Clean up.
adoRecordset.Close
Set adoRecordset = Nothing
adoConnection.Close