﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Administering / SQL Server 2005  / Create Login from master / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 04:35:25 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Create Login from master</title><link>http://www.sqlservercentral.com/Forums/Topic446786-146-1.aspx</link><description>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.</description><pubDate>Thu, 17 Dec 2009 11:57:41 GMT</pubDate><dc:creator>MannySingh</dc:creator></item><item><title>RE: Create Login from master</title><link>http://www.sqlservercentral.com/Forums/Topic446786-146-1.aspx</link><description>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.</description><pubDate>Thu, 17 Dec 2009 11:36:55 GMT</pubDate><dc:creator>DLathrop</dc:creator></item><item><title>RE: Create Login from master</title><link>http://www.sqlservercentral.com/Forums/Topic446786-146-1.aspx</link><description>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)</description><pubDate>Thu, 24 Jan 2008 04:05:50 GMT</pubDate><dc:creator>Chandrachurh Ghosh</dc:creator></item><item><title>RE: Create Login from master</title><link>http://www.sqlservercentral.com/Forums/Topic446786-146-1.aspx</link><description>You maps a login or a user to a particular database only after creating the user.</description><pubDate>Thu, 24 Jan 2008 02:23:28 GMT</pubDate><dc:creator>Ratheesh.K.Nair</dc:creator></item><item><title>Create Login from master</title><link>http://www.sqlservercentral.com/Forums/Topic446786-146-1.aspx</link><description>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.</description><pubDate>Thu, 24 Jan 2008 02:10:45 GMT</pubDate><dc:creator>Chandrachurh Ghosh</dc:creator></item></channel></rss>