By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,589 Members | 1,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,589 IT Pros & Developers. It's quick & easy.

Updating attributes in LDAP/Active Directory

P: n/a
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(attrLis t(i))(0)

oSearchResult.GetDirectoryEntry.Properties(attrLis t(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.

Oct 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"Dave" wrote:
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(attrLis t(i))(0)

oSearchResult.GetDirectoryEntry.Properties(attrLis t(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.

Oct 21 '05 #2

P: n/a
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.

"Jakob Christensen" wrote:
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.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"Dave" wrote:
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(attrLis t(i))(0)

oSearchResult.GetDirectoryEntry.Properties(attrLis t(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.

Oct 21 '05 #3

P: n/a
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.

"Jakob Christensen" wrote:
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.
--
http://www.dotninjas.dk
http://www.powerbytes.dk
"Dave" wrote:
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(attrLis t(i))(0)

oSearchResult.GetDirectoryEntry.Properties(attrLis t(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.

Oct 21 '05 #4

P: n/a
>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

Oct 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.