简体   繁体   中英

Unable to create login with Windows or SQL Server authentication in SQL Server 2012 Standard

I am getting the following error every time I am trying to create a login (windows/sql) in SQL Server:

Query:

USE [master]

GO

CREATE LOGIN [domain\loginname] FROM WINDOWS WITH DEFAULT_DATABASE=[master]

GO

Error:

Msg 8143, Level 16, State 1, Procedure sp_send_dbmail, Line 0 [Batch Start Line 2]
Parameter '@profile_name' was supplied multiple times.

I'm unable to figure out what could be the issue. Any help will be appreciated.

Thank you

Your problem looks like is you are using a variable, and that one is never SET again. I will suggest you use that way to create your Login accounts. If you need to create multiple accounts, you can use a cursor or a while statement that loop against a temp table where you saved the domain accounts that you want to create.

SET QUOTED_IDENTIFIER OFF
go  
use master
go 

declare @domainuser SYSNAME
DECLARE @sqlCMD nvarchar(2000)
SET @domainuser = 'YourDomain\UserName'

SET @sqlCMD = N'CREATE LOGIN ['+ @domainuser +'] FROM WINDOWS WITH DEFAULT_DATABASE = [master];'

--PRINT @sqlCMD
EXEC (@sqlCMD)
GO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM