473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Updating attributes in LDAP/Active Directory

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
4 4904
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
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
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
>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Victor Lokhmatov | last post by:
Hello Everyone, My company has asked me to put a company directory on our intranet site and I'm trying to use php to extract the users from our active directory server. I've got everything...
0
by: Stressed Monkey | last post by:
Hi, Does anyone know how to update a field in an LDAP directory using ASP? (I don't mean in active directory but I guess if it can be done in that then the concept could be applied to another...
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
2
by: Mesut KoÅŸucu | last post by:
hi all i get a error when update user attributes the error is "General access denied error " the code is Dim strAttrName As String = Me.TextBox1.Text Dim strAttrValue As String =...
7
by: Sync Walantaji | last post by:
Hi, I would like to write a asp.net winform program to authenticate users on Active Directory. Can I do this with asp.net if the IIS server is not part of the Active directory domain? Is...
4
by: h2so4 | last post by:
I want to write a program that will query an ldap directory. can I use adsi or ado to do that, If yes how ? tx -- h2so4
1
by: Keith Jakobs, MCP | last post by:
HELP!!!! VB.NET has been a thorn in my side, but trying to use the System.DirectoryServices namespace has to be one of the most ridiculously confusing classes I have EVER encountered!!!! Am I...
0
by: RTT | last post by:
here is my current situation. I develop a program on my computer's localhost. From there i contact Active directory succesfull using a connectionstring like:...
4
by: Dave | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.