ここで何が間違っているのかよくわかりません。
Active Directory からいくつかの値を取得して、SQL サーバー データベースに挿入しようとしています。
23 行目で「プロバイダー: 未指定のエラー」というエラーが発生し続けます。
これは 23 行目です --> Set 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