Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Create Login from master


Create Login from master

Author
Message
Chandrachurh Ghosh
Chandrachurh Ghosh
SSC Veteran
SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)

Group: General Forum Members
Points: 203 Visits: 331
Is there any way I can create a login for a database while the database context is master or not the particular database.
Actually, the database will be known during runtime, and a login needs to be created.

Chandrachurh Ghosh
DBA – MS SQL Server
Ericsson India Global Services Limited
Quality is not an act, it is a habit.
VastSQL
VastSQL
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3028 Visits: 5017
You maps a login or a user to a particular database only after creating the user.
Chandrachurh Ghosh
Chandrachurh Ghosh
SSC Veteran
SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)SSC Veteran (203 reputation)

Group: General Forum Members
Points: 203 Visits: 331
That is true. I am already able to create the login, but cannot grant connect to the database....It says the login is not available or you do not have permission...

----------------------CREATE LOGIN-----------------------------------------------
declare @SQL_DB varchar(20),
@STRSQL1 varchar(500),
@STRSQL2 varchar(500),
@STRSQL3 varchar(500),
@STRSQL4 varchar(500)

SET @SQL_DB='USE '+@DATABASE_NAME
SET @STRSQL1=(' IF NOT EXISTS (SELECT *
FROM sys.server_principals
WHERE name='''+@DB_USER+''')')
SET @STRSQL2=(' BEGIN
CREATE LOGIN '+@DB_USER+'
WITH PASSWORD=N'''+@DB_USER+''',
DEFAULT_DATABASE=['+@DATABASE_NAME+'],
DEFAULT_LANGUAGE=[us_english],
CHECK_EXPIRATION=OFF,
CHECK_POLICY=OFF
END')
SET @STRSQL3=(' EXEC sys.sp_addsrvrolemember @loginame = N'''+@DB_USER+''', @rolename = N''sysadmin''')
SET @STRSQL4=(' ALTER LOGIN ['+@DB_USER+'] DISABLE')
EXEC (@SQL_DB+@STRSQL1+@STRSQL2+@STRSQL3+@STRSQL4)
------------------------CREATE USER----------------------------------------------
SET @STRSQL1=(' IF NOT EXISTS (SELECT *
FROM '+@DATABASE_NAME+'.sys.server_principals
WHERE name='''+@DB_USER+''')')
SET @STRSQL2=(' CREATE USER ['+@DB_USER+']
FOR LOGIN ['+@DB_USER+']
WITH DEFAULT_SCHEMA=[dbo]')
EXEC (@SQL_DB+@STRSQL1+@STRSQL2+@STRSQL3)

SET @STRSQL1=(' GRANT CONNECT TO ['+@DB_USER+']')
EXEC (@SQL_DB+@STRSQL1)

Chandrachurh Ghosh
DBA – MS SQL Server
Ericsson India Global Services Limited
Quality is not an act, it is a habit.
DLathrop
DLathrop
SSC Journeyman
SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)SSC Journeyman (90 reputation)

Group: General Forum Members
Points: 90 Visits: 219
According to BOL, the CREATE USER statement is "Requires ALTER ANY USER permission on the database." This will be in addition to having EXECUTE permission on your stored procedure in the database where this code resides and/or is executed. You need to check the permissions required in the database to GRANT CONNECTION and anything else being done within the database. E.g., GRANT EXECUTE minimally requires having CONTROL permission on that object.

David Lathrop
DBA
WA Dept of Health
MannySingh
MannySingh
SSChasing Mays
SSChasing Mays (649 reputation)SSChasing Mays (649 reputation)SSChasing Mays (649 reputation)SSChasing Mays (649 reputation)SSChasing Mays (649 reputation)SSChasing Mays (649 reputation)SSChasing Mays (649 reputation)SSChasing Mays (649 reputation)

Group: General Forum Members
Points: 649 Visits: 777
Is this a single login or is the application creating logins at runtime too.. Pl describe how the logins/users are created vias the application.

Maninder
www.dbanation.com
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search