468,268 Members | 1,713 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,268 developers. It's quick & easy.

Membership Provider: how to create initial user acct. after deploy

Hello,

I have a web application that makes use of the SQL Membership and Role
providers. My app has admin screens to manage users (membership), roles, and
supplementary user data. I have just deployed the application to a
production server.

My Question: How do I create the initial Admin role and user in the
clean/unpopulated database that has the Membership and Role schema on this
production server?

The production server does not have the Visual Studio solution/project, it
only has the project deliverables.

Thanks for your help,

Josh Blair
HydraForce, Inc.
Nov 20 '07 #1
1 2706
You can either write your own little application.

I've written one, which uses 3 text files as the source. Users, Roles, and
UserToRoles.
This is "owned' code so I can't share it.
I wrote a console application, which reads these 3 files..and then does the
Membership.CreateUser type calls through it.
...

You can use the "create tsql code" helper I made:
THis will generate the Tsql code...that you can run on the production
database.

Note, this code generates tsql code. It does not actually perform the
inserts.

Also note that an Application/RoleName/UserName with a single quote in the
name will make the script create bad code.

-------START TSQL
SET NOCOUNT ON
print '-- You probably should set your "Results To Text"'
print '-- You need to copy and paste the OUTPUT of this query..and run
against a different aspnetdb membership/roles db'
print ''
print ''
--**************************************************
print 'SET NOCOUNT ON'
--**************************************************
print '/*'
print '--These next delete lines are optional, but if you want a clean
transfer, you can run them (uncomment them)'
print 'delete from dbo.aspnet_Membership'
print 'delete from dbo.aspnet_UsersInRoles'
print 'delete from dbo.aspnet_Roles'
print 'delete from dbo.aspnet_Profile'
print 'delete from dbo.aspnet_Users'
print 'delete from dbo.aspnet_Applications'
print '*/'
print ''
print ''

--**************************************************

select
'INSERT INTO dbo.aspnet_Applications (
ApplicationName,LoweredApplicationName,Application Id,[Description] ) values
(' as [--Comment],
char(39) + t1.ApplicationName + char(39) , ',' ,
char(39) + t1.LoweredApplicationName + char(39) , ',' ,
char(39) + convert(varchar(38) , t1.ApplicationId ) + char(39) , ',' ,
char(39) + t1.Description + char(39)
, ')'
FROM
dbo.aspnet_Applications t1

--**************************************************

-- select top 1 * from dbo.aspnet_Roles
--ApplicationId,RoleId,RoleName,LoweredRoleName,[Description]
Select
'INSERT INTO dbo.aspnet_Roles (
ApplicationId,RoleId,RoleName,LoweredRoleName,[Description] ) values (' as
[--Comment],
char(39) + convert(varchar(38) , t1.ApplicationId ) + char(39) , ',' ,
char(39) + convert(varchar(38) , t1.RoleId ) + char(39) , ',' ,
char(39) + t1.RoleName + char(39) , ',' ,
char(39) + t1.LoweredRoleName + char(39) , ',' ,
char(39) + t1.Description + char(39)
, ')'
FROM
dbo.aspnet_Roles t1

--**************************************************

--select top 1 * from dbo.aspnet_Users
--ApplicationId,UserId,UserName,LoweredUserName,Mobi leAlias,IsAnonymous,LastActivityDate
Select
'INSERT INTO dbo.aspnet_Users (
ApplicationId,UserId,UserName,LoweredUserName,Mobi leAlias,IsAnonymous,LastActivityDate
) values (' as [--Comment] ,
char(39) + convert(varchar(38) , t1.ApplicationId ) + char(39) , ',' ,
char(39) + convert(varchar(38) , t1.UserId ) + char(39) , ',' ,
char(39) + t1.UserName + char(39) , ',' ,
char(39) + t1.LoweredUserName + char(39) , ',' ,
char(39) + t1.MobileAlias + char(39) , ',' ,
IsAnonymous, ',' ,
char(39) + convert(varchar(38) , t1.LastActivityDate ) + char(39)
, ')'
FROM
dbo.aspnet_Users t1

--**************************************************
print ''
print '--TO DO-- dbo.aspnet_Profile'
print '--I did not utilize the Profile information, so I didnt code it
up....you can follow the pattern and implement Profile information here'
print ''
print ''
--**************************************************
--select top 1 * from dbo.aspnet_UsersInRoles
--UserID, RoleID
Select
'INSERT INTO dbo.aspnet_UsersInRoles ( UserID, RoleID ) values (' as
[--Comment],
char(39) + convert(varchar(38) , t1.UserID ) + char(39) , ',' ,
char(39) + convert(varchar(38) , t1.RoleID ) + char(39)
, ')'
FROM
dbo.aspnet_UsersInRoles t1

--**************************************************

-- select top 1 * from dbo.aspnet_Membership
--ApplicationId,UserId,Password,PasswordFormat,Passw ordSalt,MobilePIN,Email,LoweredEmail,PasswordQuest ion,PasswordAnswer,IsApproved,IsLockedOut,CreateDa te,LastLoginDate,LastPasswordChangedDate,LastLocko utDate,FailedPasswordAttemptCount,FailedPasswordAt temptWindowStart,FailedPasswordAnswerAttemptCount, FailedPasswordAnswerAttemptWindowStart,Comment
--ApplicationId,UserId,[Password],PasswordFormat,PasswordSalt,
--MobilePIN,Email,LoweredEmail,PasswordQuestion,Pass wordAnswer,
--IsApproved,IsLockedOut,CreateDate,LastLoginDate,La stPasswordChangedDate,
--LastLockoutDate,FailedPasswordAttemptCount,FailedP asswordAttemptWindowStart,FailedPasswordAnswerAtte mptCount,FailedPasswordAnswerAttemptWindowStart,
--Comment
Select
'INSERT INTO dbo.aspnet_Membership (
ApplicationId,UserId,[Password],PasswordFormat,PasswordSalt,MobilePIN,Email,Lower edEmail,PasswordQuestion,PasswordAnswer,IsApproved ,IsLockedOut,CreateDate,LastLoginDate,LastPassword ChangedDate,LastLockoutDate,FailedPasswordAttemptC ount,FailedPasswordAttemptWindowStart,FailedPasswo rdAnswerAttemptCount,FailedPasswordAnswerAttemptWi ndowStart,Comment
) values (' as [--Comment],
char(39) + convert(varchar(38) , t1.ApplicationId ) + char(39) , ',' ,
char(39) + convert(varchar(38) , t1.UserId ) + char(39) , ',' ,
char(39) + t1.[Password] + char(39) , ',' ,
PasswordFormat , ',' ,
char(39) + t1.PasswordSalt + char(39) , ',' ,
char(39) + t1.MobilePIN + char(39) , ',' ,
char(39) + t1.Email + char(39) , ',' ,
char(39) + t1.LoweredEmail + char(39) , ',' ,
char(39) + t1.PasswordQuestion + char(39) , ',' ,
char(39) + t1.PasswordAnswer + char(39) , ',' ,
IsApproved , ',' ,
IsLockedOut , ',' ,
char(39) + convert(varchar(38) , t1.CreateDate) + char(39) , ',' ,
char(39) + convert(varchar(38) , t1.LastLoginDate) + char(39) , ',' ,
char(39) + convert(varchar(38) , t1.LastPasswordChangedDate) + char(39) ,
',' ,
char(39) + convert(varchar(38) , t1.LastLockoutDate) + char(39) , ',' ,
FailedPasswordAttemptCount , ',' ,
char(39) + convert(varchar(38) , t1.FailedPasswordAttemptWindowStart) +
char(39) , ',' ,
FailedPasswordAnswerAttemptCount , ',' ,
char(39) + convert(varchar(38) ,t1.FailedPasswordAnswerAttemptWindowStart )
+ char(39) , ',' ,
char(39) + convert(varchar(1028) , t1.Comment) + char(39)
, ')'

FROM
dbo.aspnet_Membership t1

--**************************************************

print ''
print ''
print 'Select * from dbo.aspnet_Applications'
print 'Select * from dbo.aspnet_Users'
print 'Select * from dbo.aspnet_Profile'
print 'Select * from dbo.aspnet_Roles'
print 'Select * from dbo.aspnet_UsersInRoles'
print 'Select * from dbo.aspnet_Membership'


"hfdev" <hf***@discussions.microsoft.comwrote in message
news:5F**********************************@microsof t.com...
Hello,

I have a web application that makes use of the SQL Membership and Role
providers. My app has admin screens to manage users (membership), roles,
and
supplementary user data. I have just deployed the application to a
production server.

My Question: How do I create the initial Admin role and user in the
clean/unpopulated database that has the Membership and Role schema on this
production server?

The production server does not have the Visual Studio solution/project, it
only has the project deliverables.

Thanks for your help,

Josh Blair
HydraForce, Inc.

Nov 20 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John | last post: by
9 posts views Thread by Paul Keegstra | last post: by
3 posts views Thread by Carlos | last post: by
4 posts views Thread by =?Utf-8?B?Q2hyaXMgQ2Fw?= | last post: by
2 posts views Thread by GaryDean | last post: by
3 posts views Thread by GaryDean | last post: by
6 posts views Thread by Jonathan Wood | last post: by
3 posts views Thread by dm3281 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.