I'm trying to query data from an Azure SQL database using an Azure Web API, and I can't seem to determine how for format the SQL connection string.
The user assigned managed identity has been added to "Access control" for the SQL Server and added as an Identity for the Web API. In addition, the user assigned managed identity has been added as an identity for the server.
I also added the user assigned managed identity as a contained login and role using:
CREATE USER [<Name of user assigned identity>] FROM EXTERNAL PROVIDER;
ALTER ROLE db_datareader ADD MEMBER [<Name of user assigned identity>];
I've tried using the following as a connection string:
'Server=tcp:mxtestdbserver.database.windows.net,1433;Initial Catalog={databaseName};Persist Security Info=False;User ID={userAssignedClientName};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication=\"Active Directory Integrated\";'
But I get the following error:
Failed to authenticate the user <userAssignedClientName> in Active Directory (Authentication=ActiveDirectoryIntegrated). Error code 0xunknown_user_type Unsupported User Type 'Unknown'. Please see https://aka.ms/msal-net-up.
NOTE:
I've also tried the following:
"Data Source=<AZURE-SQL-SERVERNAME>; Initial Catalog=<DATABASE>; Authentication=Active Directory Managed Identity; Encrypt=True";
However, I couldn't see where to specify the User Assigned Managed Identity and I'm getting the following error:
'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'
The SQL Server is configured to allow access by azure resources.
Any insight is greatly appreciated.