Re: Some or all identity references could not be translated.



Hi Joe,

it works now :))
Thank you for help.

Can you suggest me something about AD.

what I do:

create OU and then create user.
But I sometimes recive error, like there is no OU which I just created but OU is there

strDNSADDomain=
I was put just domain(domain.loc) but I then recived error frequently.
Then I put full DC name(ad1.domain.loc) but mistakes were reduce but nevertheless knows happen.

Can you suggest something??


Code:
----------

create user:

Dim ctx As New PrincipalContext(ContextType.Domain, strDNSADDomain, strOU)

Dim user As New UserPrincipal(ctx)

user.SamAccountName = strSamAccountName
If Not String.IsNullOrEmpty(strDescription) Then user.Description = strDescription
user.SetPassword(strPassword)
user.Enabled = True
user.PasswordNeverExpires = True

If Not String.IsNullOrEmpty(strUPN) Then user.UserPrincipalName = strUPN

user.Save()

user.Dispose()
ctx.Dispose()

create OU:

Dim objAD As DirectoryEntry
Dim objOU As DirectoryEntry

strOU = "OU=" + strOU

objAD = New DirectoryEntry(strPath)

objOU = objAD.Children.Add(strOU, "OrganizationalUnit")
If Not String.IsNullOrEmpty(strDescription) Then objOU.Properties("description").Add(strDescription)
If Not String.IsNullOrEmpty(struPNSuffix) Then objOU.Properties("uPNSuffixes").Add(struPNSuffix)
objOU.CommitChanges()

objOU.Dispose()
objAD.Dispose()

Error:
-------

There is no such object on the server. -- at System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit() at System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit() at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() at System.DirectoryServices.AccountManagement.PrincipalContext.ContextForType(Type t) at System.DirectoryServices.AccountManagement.Principal.GetStoreCtxToUse() at System.DirectoryServices.AccountManagement.Principal.set_SamAccountName(String value) at serviceprovisioning.ActiveDirectory.CreateUser(String strSamAccountName, String strPassword, String strOU, String strDescription, String strUPN, String strDNSADDomain)


----------------------------------------------
#example if someone else have similar problems.

Dim identity As NTAccount

identity = New NTAccount(strUserName)

Dim sid As SecurityIdentifier =
DirectCast(identity.Translate(GetType(SecurityIdentifier)),
SecurityIdentifier)

Dim dInfo As New DirectoryInfo(strFolderName)
Dim dSecurity As DirectorySecurity =
dInfo.GetAccessControl(AccessControlSections.Access)

dSecurity.AddAccessRule(New FileSystemAccessRule(sid, _
rights, _
iFlags, _
pFlags, _
acType))

dInfo.SetAccessControl(dSecurity)



.



Relevant Pages

  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)
  • Auto Write Name and Merge across
    ... Dim Sheetname01 As String ... Dim WeekName01 As String ...
    (microsoft.public.excel.misc)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Help answer these 70-310 questions
    ... One argument is the string ... Dim output As New StringBuilder ... EmployeeLocations. ... You create a strongly named serviced component. ...
    (microsoft.public.cert.exam.mcad)