Creating SqlExpress role manager database

D

David Thielen

Hi;

We don't want to put the 10M MDF file in our install. I figure it's much
better just to run a script to create it on each customer's server. So...

1) How can we programatically create the ASPNETDB.MDF database?

2) How can we programatically create several groups?

3) How can we programatically create a user (the admin user)?
 
S

Steven Cheng[MSFT]

Hi Dave,

Thank you for posting.

From your description, you're going to develop an websetup project for your
ASP.NET 2.0 web application, and this application uses a SQL EXPRESS mdf
file as the membership/role management service's data storge. Currently
you're wondering how to create such as database file programmatically in
the setup application on the target machine rather than copy an existing
one (packaged in the setup package) , correct?

Based on my research, here are some of suggestion on this:

To programmatically create such a SQL Express database, the common means is
to connect to the SQL Express instance on the target machine and executing
some T-SQL scripts to create the database. So firstly, our setup project
will first help ensure the SQLEXPRESS engine has been installed. This can
be done by selecting the SQL EXPRESS as prerequisites. After that, we can
create the ASP.NET service database through the following steps:

1. Connect to the SQL EXPRESS instance and then run T-SQL script to create
a "database" (have a look at the "Create Database" T-SQL script). This can
be done through some ADO.NET code in a custom action assemby or executable
file.

2. After you have created the sqlexpress database in the SQL EXPRESS
instance, you can then call the aspnet_regsql.exe command line utility to
create the database tables for membership/role service in that created
database.

#ASP.NET SQL Server Registration Tool (Aspnet_regsql.exe)
http://msdn2.microsoft.com/en-us/library/ms229862.aspx

e.g. "aspnet_regsql.exe -E -S localhost\SQLEXPRESS -d MyASPNETDB -A mr"

3. I think this step will be the most difficult one if you want to add some
initial data(such as some use accounts into the membership database
tables). As far as I know, after go through the step #2
(aspnet_regsql.exe), it has created those store procedures which will help
do the SqlMembership/role managment service's operations in our specified
database. However, for creating new users, there's some parameter that need
particular customization when we directly call those SQL store procedure to
inssert them into database. For example, the user account's password may
need to be hashed(when we set passwordFormat = "hashed" ). So the best
approach is call the "SqlMemberShipProvider" class's method to create such
users. I've lookup the SqlMembershipProvider class, we can manually create
it in our own application(not necessary asp.net application), and it is its
"Initialize" method that will be important to supply the sufficient
information for initializing the database info. I suggest you have a look
its internal code logic through reflector tool so that you'll get what
information you'll have to manually supply in your custom code. And one
paramter is the connectionString parameter which require the
connectionString to be stored in the application's configure file (in the
<connectionStrings> section). Therefore, I recommend you encapsulate all
these customAction code into an console application (which can have a
app.config file with it to store some necessary info) and configure to
launch it in your web setup project.

Just some of my personal ideas and due to the complexity I haven't tried a
complete test but I think it a possible way. Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

Yes, quite hard if you need to intializing some ASP.NET membership database
specific data in your setup program(at that time the ASP.NET application
runtime context is still not available...).

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top