WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADSI
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

1073 Cannot Contact the LDAP Server


Question:

Can anyone help me with this error (1073: cannot contact the LDAP server) that I keep getting when running the following code? The code begins to process and looks like it is running fine but then the error appears and stops the program. If I eliminate some of the dsGetProperty lines the code will run longer but still error out.

Any help would be greatly appreciated.

AddExtender("wwads34i.dll")
AddExtender("wwsop34i.DLL")

title = "Check User Logons - v1.00"
boxtitle(title)
today = TimeYmdHms()
days90 = TimeSubtract(today, "0000:00:90:00:00:00")
data = ""

sStarPath = "LDAP://corpdc03.corp.ent.MYDOMAIN.org/DC=corp,DC=ent,DC=MYDOMAIN,DC=org"

sFilter = `(&(objectCategory=Person)(lastlogon<=%days90%))` ;search for lastlogon property greated than 90 days old
astatusbar(0,title,"Generating AD User List...",0,0)
MyOuPaths = dsFindPath(sStarPath, sFilter)
y = 0
oucount = itemcount(myoupaths,@tab)
for x = 1 to oucount
	astatusbar(1,title,"Checking User Logons... 90 Day Old",oucount,x)
	ou = itemextract(x,myoupaths,@tab)
	cn = dsGetProperty(ou, "cn")
	ll = dsGetProperty(ou, "lastlogon")
	if ll != 0 then ll = timediffdays(today,ll)
	lastname = dsGetProperty(ou, "sn")
	firstname = dsGetProperty(ou, "givenname")
	parentou = dsGetProperty(dsGetPrntPath(ou), "CN")
	createdate = timediffdays(today,dsGetProperty(ou, "createTimeStamp"))
	data = strcat(data,cn,",",lastname,",",firstname,",",parentou,",",ll,@crlf)
next

sFilter = "(&(objectCategory=Person)(!lastlogon=*))" ;search for empty lastlogon property
astatusbar(0,title,"Generating AD User List...",0,0)
MyOuPaths = dsFindPath(sStarPath, sFilter)
y = 0
oucount = itemcount(myoupaths,@tab)
for x = 1 to oucount
	astatusbar(1,title,"Checking User Logons... Empty Values",oucount,x)
	ou = itemextract(x,myoupaths,@tab)
	cn = dsGetProperty(ou, "cn")
	lastname = dsGetProperty(ou, "sn")
	firstname = dsGetProperty(ou, "givenname")
	parentou = dsGetProperty(dsGetPrntPath(ou), "CN")
	createdate = timediffdays(today,dsGetProperty(ou, "createTimeStamp"))
	data = strcat(data,cn,",",lastname,",",firstname,",",parentou,",0",@crlf)
next

astatusbar(2,title,"",0,0)
logfile = fileopen("c:\Log.txt","write")
filewrite(logfile,data)
fileclose(logfile)
message("","Done!")

Answer:

It would be helpful to know which line or lines it is failing on. Also the error is being generated by the underlying directory service. The extender is just reporting what the system is telling it. It could actually be that the server is unavailible long enough to cause a time out.

dsFindPath error

If the error occurs on the dsFindPath. The most likely cause is the server is temporarily unavailable. Note: You can easily force this error by simply passing a BAD server name:

AddExtender("WWADS44I.DLL")
dcName  ="DummyName"
samName = "Whatever"
sFilter ="(&(objectCategory=Person)(sAMAccountName=%samName%))"
dcPath = StrCat("LDAP://%dcName%/","DC=App,DC=Ad,DC=domain,DC=net")
ouPath = dsFindPath(dcPath,sFilter)
I would recommend adding code to your script that captures all 1073 errors and logs them out to a file along with details about the servername and the time the error occured. It might help you track down the problem on your network.

dsGetProperty error

You could try re-writing the script using WB's OLE/COM implementation. The extender tends to fetch data from the server "on the wire", whereas using OLE (like VB script does) will pull all the properties of an object into a local cache and fetch individual values without re-contacting the server. If your server is heavily tasked this may fix your problem. This could also potentially fix the problem, if it is being caused by an extender bug.

User reply:

The error always seems to fail on a "dsGetProperty" line but not the same one. It seems to be random. I'll look into OLE/COM solution.

Answer:

When the ADSI extender was written we really didn't have a feel for how people would use it. We opted to make it easy to use with as few steps as possible. We felt that it was the only way to give it some advantage over VBS or VB and COM. One way we did this was to remove the need save cached object changes to the Directory Service. The extender does this in the background every time you make a change to a property. While this makes ADSI a little less error prone and easier to use, it also adds a lot of network traffic. (With straight COM objects you have to tell ADSI to update the DS with your cached changes or they are lost.)

The problem is that the extender is prone to timing issue because of all the extra network traffic it generates.

There are several points to keep in mind here.

  1. Active Directory servers have a built-in throttle that will cause time-out errors when too many connections in a given time so network load is not the issue. It is possible to get timeout errors with COM as well as with the extender. The extender is just a little more prone to this sort of thing because it causes an authentication check on every property submission.

  2. Generally, the extender will only generate error 1073 when doing bulk updates of many properties to many objects. Under other conditions it is not normal an issue with the extender anymore than it is with COM.

  3. There is an interesting trick that can be used to avoid the 1073 error with the extender. You can keep the connect from a client to a the AD server open by creating an AD COM object at the beginning of your script. This will cause all subsequent extender access to use the existing connection without re-authenticating and thus prevent the 1073 error. Note that you must use the same credentials for both COM and the extender for this to work properly.

Here is some revised code that uses COM instead of dsGetProperty to grab those user properties.

AddExtender("wwads34i.dll")                                                                                                                                                                                                                                
AddExtender("wwsop34i.DLL")
                           
title = "Check User Logons - v1.00"
BoxTitle(title)
today = TimeYMDHMS()
days90 = TimeSubtract(today, "0000:00:90:00:00:00")
data = ""
                        
sadsipath="LDAP://rootDSE"
svalue=dsGetProperty (sadsipath,"defaultNamingContext")
sstarpath=StrCat("LDAP://",svalue)
                                                                                                                                                                                                                                                           
sfilter = `(&(objectCategory=Person)(lastlogon<=%days90%))` ; Search for lastlogon property greated than 90 days old.
aStatusBar(0,title,"Generating AD User List...",0,0)
myoupaths = dsFindPath(sstarpath, sfilter)
oucount = ItemCount(myoupaths,@Tab)
For x = 1 To oucount
  aStatusBar(1,title,"Checking User Logons... 90 Day Old",oucount,x)
  ou = ItemExtract(x,myoupaths,@Tab)
  objuser = ObjectOpen(ou)
  cn = objuser.cn
  ll = objuser.lastlogon
  If ll != 0 Then ll = TimeDiffDays(today,ll)
  lastname = objuser.sn 
  firstname = objuser.givenname
  parentou = objuser.parent 
  createdate = TimeDiffDays(today,objuser.createtimestamp)
  data = StrCat(data,cn,",",lastname,",",firstname,",",parentou,",",ll,",",createdate,@CrLf)
  ObjectClose(objuser)
Next

sfilter = "(&(objectCategory=Person)(!lastlogon=*))" ; Search for empty lastlogon property.
aStatusBar(0,title,"Generating AD User List...",0,0)
myoupaths = dsFindPath(sstarpath, sfilter)                                                                                                                                                                                                                                                      
oucount = ItemCount(myoupaths,@Tab)
For x = 1 To oucount
  aStatusBar(1,title,"Checking User Logons... Empty Values",oucount,x)
  ou = ItemExtract(x,myoupaths,@Tab)
  objuser = ObjectOpen(ou)
  cn = objuser.cn
  lastname = objuser.sn
  firstname = objuser.givenname
  parentou = objuser.parent
  createdate = TimeDiffDays(today,objuser.createtimestamp
  data = StrCat(data,cn,",",lastname,",",firstname,",",parentou,",",createdate,@CrLf)
  ObjectClose(objuser)
Next 
aStatusBar(2,title,"",0,0)
logfile = FileOpen("c:\Log.txt","write")
FileWrite(logfile,data)
FileClose(logfile)                                                                                                                                                                                                                                         



Article ID:   W15797
File Created: 2010:10:07:12:54:10
Last Updated: 2010:10:07:12:54:10