Asked by:
Batch loading users into AspNetUsers

Question
-
Hi;
Using VS 2017, SQL Server
I’ve had a web app built that requires users to log in. I need the ability to load users in batches, for example from a spreadsheet. This functionality will be in an administrator app, Windows , not Web. Since the Web app has security, I already have the AspNetUsers and related tables in the database.
I’m a near total Newb at VS. but want to start programming some of this myself. I have part of the Administrator piece built and connected to the database already, I'm now ready to add this user import function.
Let’s say I have each user’s email address, user name and DOB; and lets say I'm going to use the DOB as a temporary password.
I’ve been looking for sample code I could use as a framework to build on, but have been unable to find any.
Thanks for any help.
- Moved by Sara LiuMicrosoft contingent staff Tuesday, March 20, 2018 6:27 AM
Thursday, March 8, 2018 2:27 AM
All replies
-
Hi Rol3D,
Welcome to the MSDN forum.
>> I’ve had a web app built that requires users to log in.
What’s the type of your web app? What project template are you using in Visual Studio?
>> This functionality will be in an administrator app, Windows , not Web.
Do you mean you want to add the user import function on a windows application?
This forum is discussing Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System, and Visual Studio Editor.
And if your issue is related to Web Forms development, I suggest you go to asp.net forum to get a professional answer. If your issue is not related to asp.net, please tell me, and I will help you move this thread to corresponding forum for a professional answer.
Thanks for your understanding.
Regards,
Judyzh
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Thursday, March 8, 2018 8:37 AM -
I don't know the specifics of your environment, but you if it's an Excel file you need to export/import to SQL Server then you should be able to do this with an INSERT...SELECT query. Here is an example:
Dim ExcelConnection As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" & _ "Data Source=" & "c:\Test Files\Book20.xls" & ";" & _ "Extended Properties=""Excel 12.0 Xml;HDR=YES""") ExcelConnection.Open() Dim ExcelCommand As New System.Data.OleDb.OleDbCommand("INSERT INTO [ODBC;Driver={SQL Server Native Client 11.0};Server=(local);Database=DBName;Trusted_Connection=yes].[TABLE] (Col1, Col2) SELECT Col1, Col2 FROM [Worksheet$];", ExcelConnection) ExcelCommand.ExecuteNonQuery() ExcelConnection.Close()
Paul ~~~~ Microsoft MVP (Visual Basic)
Thursday, March 8, 2018 2:08 PM -
Hi Judyzh and thanks for your answer.
I dont know what template they used, but it is a web based system; I do know that the login authentication is via AspNetUser and related tables.
I do not want this new, support system to be web based, so yes, it is a Windows program. It supports a number of functions, such as reporting. To it, I want to add this new functionality that supports loading large (1000's) of users in batch mode from a standard spread sheet. I have no problem loading the spread sheet, the question is how to I add users to the AspNetUsers table and have the password generated in batch mode, i.e. for all 1000's at once.
My 'hope' is it's a simple as loading the spreadsheet into a table, then looping throught that table and for each entry, inserting a record into AspNetUsers, having the password hash generated and then inserting a record into AspNetUserRole.
Many Thanks
Thursday, March 8, 2018 3:23 PM -
Thanks, I have no problem inserting the records into AspNetUsers, but how does the password hash get generated?
Thursday, March 8, 2018 4:49 PM -
... I forgot to mention, I'm C#.
- Edited by Rol3D Thursday, March 8, 2018 5:07 PM
Thursday, March 8, 2018 5:06 PM -
Are you using the Membership Provider with SQL Server? It isn't clear to me how the Administrator piece was constructed. If you are using the Membership provider then you can use the Membership Classes to add users to the database. Instead of importing directly from the Excel Worksheet you can read in all of the user information using a SQL SELECT statement and then for each one use the Membership Classes to add the users to the database:
https://msdn.microsoft.com/en-us/library/system.web.security.membershipuser(v=vs.110).aspx
https://msdn.microsoft.com/en-us/library/d8t4h2es(v=vs.110).aspx
Paul ~~~~ Microsoft MVP (Visual Basic)
- Proposed as answer by Judy ZhuY Thursday, March 15, 2018 9:48 AM
Thursday, March 8, 2018 11:10 PM