Monday, February 20, 2012

Looking for direction on how to add 4000+ users into ASPNETDB manually

Hello and thanks for reading,

I would like to know if it's possible to add around 4000 users into the ASPNETDB without adding them one at a time. I have to avoid using a "create user wizard" because this login is for a private online election only. The list of users is in an access database and looks like this:

Username Password

DHunziker Hu8645

SEnderton En0854

BAckler Ac9576

...

Unfortunately, I don't have valid emails for all 4000 people, nor do I have the time and resources to collect security questions and answers so I don't know if this is even possible. Can you help me?

Thanks!

Peter Kellner (http://peterkellner.net/zdm_1_2/index.php) provides a nice membership management tool for this database and you can download from his site.

You can use his objectdatasource to do the batch insert. Here is a sample from a button click:

Create a SpreadSheet with these columns: UserName,password, and email.

Import this excel file to this database as table: yourUsers$

Here is the code for the button click:

protected void batchInsertButton_Click(object sender, EventArgs e) {string strConn = ConfigurationManager.ConnectionStrings["1ConnectionString"].ConnectionString;string strSQL ="SELECT * FROM yourUsers$"; SqlConnection myConnection =new SqlConnection(strConn); myConnection.Open(); SqlCommand myCommand =new SqlCommand(strSQL,myConnection); SqlDataReader myReader; myReader = myCommand.ExecuteReader();while (myReader.Read()) { ObjectDataSourceMembershipUser.InsertParameters["UserName"].DefaultValue = myReader["UserName"].ToString();//TextBoxUserName.Text; ; ObjectDataSourceMembershipUser.InsertParameters["password"].DefaultValue = myReader["password"].ToString();//TextBoxPassword.Text; ObjectDataSourceMembershipUser.InsertParameters["passwordQuestion"].DefaultValue ="your qestion";//TextBoxPasswordQuestion.Text; ObjectDataSourceMembershipUser.InsertParameters["passwordAnswer"].DefaultValue ="your answer";//TextBoxPasswordAnswer.Text; ObjectDataSourceMembershipUser.InsertParameters["email"].DefaultValue = myReader["email"].ToString();//TextBoxEmail.Text; ObjectDataSourceMembershipUser.InsertParameters["isApproved"].DefaultValue ="true";//CheckboxApproval.Checked == true ? "true" : "false"; ObjectDataSourceMembershipUser.Insert();//hard code this user role Roles.AddUserToRole(myReader["UserName"].ToString(),"NormalUser"); } myConnection.Close(); GridViewMemberUser.DataBind(); GridViewRole.DataBind(); }

Hope this helps.

|||

Wow! Thanks!

I have already got peter's managment tool running and the information that you provided is very helpful. Thanks a million!

No comments:

Post a Comment