Updating attributes in LDAP/Active Directory

G

Guest

Hello. I am trying to update attributes in LDAP/Active directory from my
application that is written in VB.NET. I am using Directory Services to do
so. I do not get any errors during the execution of the code but directory
is not being updated. I think it has something to do with caching. I do not
understand how directory services library handles it. Can someone please
help. Here is the sample of my code:


Try
mDirectoryEntry.AuthenticationType = AuthenticationTypes.SecureSocketsLayer

mDirectoryEntry.Username = distName
mDirectoryEntry.Password = pwd
mDirectoryEntry.UsePropertyCache = True
Catch ex As Exception
End Try

Dim oSearcher As DirectorySearcher
Dim oSearchResult As SearchResult
Try
oSearcher = New DirectorySearcher(mDirectoryEntry)
oSearcher.Filter = "some filter"

oSearcher.PropertiesToLoad.AddRange(attribute list)
oSearchResult = oSearcher.FindOne()

…

Dim oldValue As String =
oSearchResult.GetDirectoryEntry.Properties(attrList(i))(0)

oSearchResult.GetDirectoryEntry.Properties(attrList(i))(0) = itemValue

oSearchResult.GetDirectoryEntry.CommitChanges()
Catch ex As Exception
Finally
If Not oSearcher Is Nothing Then oSearcher.Dispose()
oSearcher = Nothing
oSearchResult = Nothing
End Try


Can also someone explain me how UsePropertyCache and RefreshCache work?

Thanks in advance for your help.
 
G

Guest

Just checking - are you sure you are not getting any errors? There are a
couple of empty catch blocks in your code that might "swallow" any exceptions
;-)

Regards, Jakob.
 
G

Guest

I did not post the actual code. It would be more difficult to explain
exactly what it is doing. I do have code for every one of the try catch
blocks doing different things. There are no errors being caught by error
handling. It seems that all updates are local to the cached version of the
data on my computer and it does not go to the directory at all.
 
G

Guest

I was working with our LDAP admin and he did not see any update requests
going to ldap from me. he sees me binding and requesting some attributes but
no updates.
 
M

Marc Scheuner [MVP ADSI]

Hello. I am trying to update attributes in LDAP/Active directory from my
application that is written in VB.NET. I am using Directory Services to do
so. I do not get any errors during the execution of the code but directory
is not being updated. I think it has something to do with caching. I do not
understand how directory services library handles it. Can someone please
help.

The problem here is this - you keep calling the .GetDirectoryEntry
from your SearchResult, and you keep getting back a different object.
This will NEVER work.....

Do it this way:

Try
oSearcher = New DirectorySearcher(mDirectoryEntry)
oSearcher.Filter = "some filter"

oSearcher.PropertiesToLoad.AddRange(attribute list)
oSearchResult = oSearcher.FindOne()

Dim YourEntry as DirectoryEntry

YourEntry = oSearchResult.GetDirectoryEntry()

....
and then go on and update all your attributes you want to update, and
finally call
YourEntry.CommitChanges();

That should do it.
Can also someone explain me how UsePropertyCache and RefreshCache work?

UsePropertyCache=true is the default and says that changes to your
properties will be cached in memory, and you will write them all back
at once when calling .CommitChanges(). if you turn it off, each change
will be written back to the AD store immediately, thus you a) cannot
just decide to discard all changes (if you screwed up somehow), and b)
your performance will suffer BIG TIME (since each property change is
written back to the AD store right away, you cause A LOT of network
traffic and updating).

RefreshCache only makes sense if you have UsePropertyCache=true, and
it will refresh the cache with values from the AD store, e.g. it will
go fetch all the values for all the properties (or all the properties
you specify) from the AD store and discard any changes you might have
made to the in-memory DirectoryEntry in the meantime. By default, you
don't need to call this - when you access a first property on the
DirectoryEntry, S.DS will do a RefreshCache in the background for you.

HTH - you might get better and more to-the-point help about LDAP and
DirectoryEntry/DirectorySearcher questions in the
microsoft.public.adsi.general newsgroup.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

LDAP Search 1
LDAP search 1
LDAP Search 1
ldap connection problem 7
system.directoryservices usage 3
LDAP Search 1
connecting problem in vb.net with ldap to active directory 4
LDAP ports not closing 2

Top