Problem while creating LDAP email account users, Value does not fall within the expected range. RRS feed

  • Question

  • User1078145427 posted

     Hi All,

     I am facing a severe issue while adding user to mailbox in Active Directory.

    When I am trying to add a user to mailbox in Active directory using ASP.NET with C# in windows server 2003 I am getting the following error.

     Value does not fall within the expected range.

     [ArgumentException: Value does not fall within the expected range.]

       CDOEXM.IMailboxStore.CreateMailbox(String HomeMDBURL) +0

       _Default.CreateUserAccountAd() +491

       _Default.btnSubmit_Click(Object sender, EventArgs e) +62

       System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105

       System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107

       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7

       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11

       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33

       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746


    Please find the code below to Create the users in windows exchange server 2003.

     DirectoryEntry dirEntry = GetDirectoryObject();

    DirectoryEntry newUser = dirEntry.Children.Add("CN=" + txtEmpName.Text.Trim() + ",CN=Users", "user");

                //create user

    newUser.Properties["samAccountName"].Value = txtEmailID.Text.Trim();

    newUser.Properties["displayName"].Value = txtDisplayName.Text.Trim();



                //set password

    newUser.Invoke("SetPassword", new object[] { txtPassword.Text.Trim() });



                //enable user

    int val = (int)newUser.Properties["userAccountControl"].Value;

    newUser.Properties["userAccountControl"].Value = val & ~0x2;




                //eXCHANGE SERVER USER

    string homeMDB = "CN=Mailbox Store(" + Helper.GetConfigValue("ExchangeStoreName") + "),CN=First Storage Group,"

                             + "CN=InformationStore,CN=" + Helper.GetConfigValue("ExchangeStoreName") + ",CN=Servers,"

      + "CN=First Administrative Group,CN=Administrative Groups,"

      + "CN=Spectraforce Technologies,CN=Microsoft Exchange,CN=Services,"

      + "CN=Configuration,DC=" + Helper.GetConfigValue("LDAPConString").Replace("LDAP://", "");



                //   CDOEXM.IMailRecipient enabledContact;

    CDOEXM.IMailboxStore mailbox = (IMailboxStore)newUser.NativeObject;






    Can you please find out where it went wrong. I am not able to identify the problem whether it is with the homeDB string or any permissions issue.

    Apprciate your help in this regard.

    Thanks in Advance,


    Wednesday, August 19, 2009 3:10 PM

All replies