Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Create Login from master Expand / Collapse
Author
Message
Posted Thursday, January 24, 2008 2:10 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 27, 2014 3:44 AM
Points: 179, 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.
Post #446786
Posted Thursday, January 24, 2008 2:23 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: 2 days ago @ 6:48 AM
Points: 2,633, Visits: 3,977
You maps a login or a user to a particular database only after creating the user.
Post #446789
Posted Thursday, January 24, 2008 4:05 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, February 27, 2014 3:44 AM
Points: 179, 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.
Post #446821
Posted Thursday, December 17, 2009 11:36 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, April 7, 2014 6:15 PM
Points: 86, Visits: 216
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
Post #835873
Posted Thursday, December 17, 2009 11:57 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Friday, August 15, 2014 11:42 AM
Points: 646, Visits: 732
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
Post #835883
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse