Search code examples
asp.netms-accesslogin-controluser-registration

ASP.net user registration page exception with MS Access


I have an ASP.net Login Control which has a link to CreateUserWizard page(register). When I fill the details and click continue, I get this error displayed.

The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.

I hope this error happens in MS Access alone...

Kindly help me to resolve this,

regards, Arjun


Solution

  • because they would create duplicate values in the index, primary key, or relationship.

    It is clear by the error message that you are trying to insert duplicate value of the primary key field in your table. Check your primary key value already exist in your table then add/insert data to your table.

    if(IsUserExist(username)
    {
    //promt user already exists
    }
    else
    {
    //insert new user detail here
    }
    

    If you are customizing this control then you have to check user exist or not.

    Check this links for help:
    Why CreateUserWizard Control automatically adds the ASPNETDB.MDF database?

    Using the Microsoft Access Providers to Replace the Built-In SQL Server Providers
    How to: Customize the ASP.NET CreateUserWizard Control

    On CreatedUser Event do check for user, :

    private bool UserExists(string username)
      {
          if (Membership.GetUser(username) != null) { return true; }
    
          return false;
      }