Please make sure you create the user database first, you get connected to the user database after that (and you are not connected to the master database) and then you execute the CREATE USER statements. Please read this documentation for more details and requirements.
Azure SQL Server invoke-sqlcmd Login failed for user token-identified principal
0
I'm trying setup Pipeline Release for automation to create User Managed Identity and add it to SQL, I have finished CREATE USER + ALTER ROLE with user AAD login to SQL Server on VM, but when I try setup on Release it stuck in auth with the error below (user AAD don't set MFA):
Anyone has ever met that before, please give me some method to resolve it. Thanks!
]2
$ResourceGroup ='AAC-BYC-NNY'
$SQLServer = 'azcacaufd1devsql01.database.windows.net'
$Database = 'Core'
$MyIdentity = 'user15'
Create User Managed Identity
az identity create --resource-group $ResourceGroup --name $MyIdentity
add UMI to sql
$query = "
CREATE USER [$MyIdentity] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [$MyIdentity];
ALTER ROLE db_datawriter ADD MEMBER [$MyIdentity];
GRANT EXECUTE TO [$MyIdentity]
GO
"
write-output "Create DB Account named $MyIdentity"
$connectString="Data Source=tcp:$SQLServer,1433;Initial Catalog=$Ddatabase;Authentication=Active Directory Password;User ID='devops@hosting.com';Password='123456';Trusted_Connection=False;Encrypt=True;Connection Timeout=30"
Invoke-Sqlcmd -ConnectionString $connectString -Query $query
2 answers
Sort by: Most helpful
-
-
Hoàng Lê Hiệp Minh 51 Reputation points
2022-11-29T03:39:53.68+00:00 The script is correct, the root cause is the value variable I have setting incorrect.
Thanks!