Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading from an SQL database

Status
Not open for further replies.

CORT1

MIS
Sep 4, 2002
12
US
I am wrighting a script to update my user attributes in the Active Directory. The script will read the first file and when it gets to the second record it gives me an error "There is no such object on the server." The account is there and it is in the same container as the first one and I can even search for it manually and find OK. Does anybody have any direction for me.
Thank you in advance
CORT1
 
Here ya go peterwestling
Let me know what you think.
Thanks,
CORT1
____________________________________________________________

Const ADS_PROPERTY_UPDATE = 2
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3
Dim objUser
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
objConnection.Open "DSN=Datasource;"
objRecordset.CursorLocation = adUseClient
objRecordset.Open "SELECT * FROM accountrequests where remoteuser = 'svc1' and dateRequested > '2003-05-23 11:00:00'and requestType = 'New Account' and updated = 0 " , objConnection,adOpenStatic,adLockOptimistic
objRecordSet.MoveFirst
Do While Not objRecordSet.EOF
strComputer = objRecordSet("remoteUser")
strUserName = objRecordSet("requestedAccount")
strFirst = objRecordSet("firstName")
strLast = objRecordSet("lastName")
strCN = strFirst & "" & strLast
strRequest = objRecordSet("comments")
strPhone = objRecordSet("phone")
strCity = objRecordSet("city")
strState = objRecordSet("state")
strAddress = objRecordSet("location")
strID = objRecordSet("id")
Set objUser = GetObject("LDAP://cn=" & strCN & ",ou=corporate,dc=cort,dc=com")
objUser.Put "givenName", strFirst
objUser.Put "sn", strLast
objUser.Put "displayName", strCN
objUser.Put "TelephoneNumber", strPhone
objUser.Put "streetAddress", strAddress
objUser.Put "L", strCity
objUser.Put "st", strState
objRecordSet("Updated") = 1
objRecordSet("dateupdated") = Now
objRecordSet("comments") = strID
objRecordSet.Update
objUser.setinfo
objRecordSet.MoveNext
Loop
Set objUser = Nothing
objRecordset.Close
objConnection.Close
MsgBox ("Accounts Update")
 
OK IM no expert and i could be wrong im pretty new to this but i think i see two problems

1. Im not positive but I think where should be all Caps. even if it doesnt have to i think its good practice.

objRecordset.Open "SELECT * FROM accountrequests where remoteuser = 'svc1' and dateRequested > '2003-05-23 11:00:00'and requestType = 'New Account' and updated = 0 " , objConnection,adOpenStatic,adLockOptimistic

2. I think this section may be your problem also because it has a problem finding the object it could be refering to the str CN.

...

strFirst = objRecordSet("firstName")
strLast = objRecordSet("lastName")
strCN = strFirst & "" & strLast

...
//( Getting object here could be error your getting)

Set objUser = GetObject("LDAP://cn=" & strCN & ",ou=corporate,dc=cort,dc=com")

why would you put

strFirst & "" & strLast

I think you meant to put

strFirst & " " & strLast
(notice the space)
Other wise it would be the same as

strFirst & strLast


Once again... I'm no expert just thought id give a stab at it

Shenn
 
shenn2
Thank you -- the problem is the space " " not ""
Thanks for your help...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top