locked
An invalid dn syntax has been specified. RRS feed

  • Question

  • User-1330916695 posted

    I am getting the follwing error when i run my script below. Please look over and see if you can find anything.

    An invalid dn syntax has been specified.

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Protected Sub Button_CreateUser_Click(sender As Object, e As EventArgs) Handles Button_CreateUser.Click

    Dim domain As String = "DC=" & DropDownList_Domain.SelectedValue

    Dim firstname As String = TextBox_FirstName.Text.ToString()
    Dim lastname As String = TextBox_LastName.Text.ToString()

    Dim users As String = "CN=Users"
    Dim comp As String = "DC=Company"
    Dim local As String = "DC=Local"

    Dim lvl1 As String = "Domain,Users,Domain,comp,Local"

    Dim ctx As New PrincipalContext(ContextType.Domain, DropDownList_Domain.SelectedValue, """ & lvl1 & """)

    Dim usr As New UserPrincipal(ctx, firstname & firstletter(), "comp1234", True)   An invalid dn syntax has been specified.
    usr.UserPrincipalName = firstname & firstletter()
    usr.SamAccountName = firstname & firstletter()
    usr.DisplayName = firstname & " " & lastname
    usr.SetPassword(comp1234)
    usr.ExpirePasswordNow()
    usr.Save()
    usr.Dispose()
    ctx.Dispose()

    End Sub

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Private Function firstletter() As String
    firstletter = TextBox_LastName.Text.Chars(0)
    End Function

    Thursday, August 1, 2013 11:48 AM

Answers

  • User1508394307 posted

    It is not a valid VB syntax. You should escape quote " with "", so full code must be 

    Dim ctx As New PrincipalContext(ContextType.Domain, """" & DropDownList_Domain.SelectedValue & """", lvl1)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 1, 2013 12:46 PM

All replies

  • User1508394307 posted

    I think, at least, this 

    """ & lvl1 & """

    is not a valid VB syntax.

    Not sure if extra quotes are required at all, try

    Dim ctx As New PrincipalContext(ContextType.Domain, DropDownList_Domain.SelectedValue, lvl1)

    Thursday, August 1, 2013 11:55 AM
  • User-1330916695 posted

    I removed those quotes......an it is still the same.....i dont know. this one is puzzling me.

    Thursday, August 1, 2013 12:05 PM
  • User-1330916695 posted

    I need to get quotes on the outside of the dropdownlist_domain.selected value.....but it wont let me do this....

    Dim ctx As New PrincipalContext(ContextType.Domain, """ & DropDownList_Domain.SelectedValue & """, lvl1)


    right now the value is ..     SRDC

    it needs to be       "SRDC"

    Thursday, August 1, 2013 12:10 PM
  • User1508394307 posted

    It is not a valid VB syntax. You should escape quote " with "", so full code must be 

    Dim ctx As New PrincipalContext(ContextType.Domain, """" & DropDownList_Domain.SelectedValue & """", lvl1)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 1, 2013 12:46 PM
  • User-1454326058 posted

    Hi scstevelong,

    Since we haven't heard from you for a long time, I temporarily close this case. I mark useful reply as answer. If you have any concerns, please free feel to reopen it or submit a new question. Thanks for your understanding.

    Thanks

    Best Regards

    Thursday, August 8, 2013 9:05 AM