0

I need to want to use Azure Active Directory User to login to the DB instead of SQL Login. The user should have access as per the privileges that are provided to him e.g. read/write, readonly, etc. I have written the code below but I am getting an exception:

string ConnectionString = @"Server=tcp:predictive-wxmstocxodfjc-dms.database.windows.net;" +
                          @"Authentication=Active Directory Integrated; Encrypt=True; User Id=UserId;";

using (SqlConnection conn = new SqlConnection(ConnectionString)) 
{
    conn.Open();
}

The user has read/write access.

Exception:

Microsoft.Data.SqlClient.SqlException (0x80131904): Failed to authenticate the user UserId in Active Directory (Authentication=ActiveDirectoryIntegrated).
Error code 0xunknown_user_type
Unsupported User Type 'Unknown'. Please see https://aka.ms/msal-net-up

Can I please get some help on this. Thanks.

codersl
  • 2,222
  • 4
  • 30
  • 33
Lily
  • 169
  • 2
  • 2
  • 11
  • Does this help answer your question? https://stackoverflow.com/questions/46681021/can-not-connect-to-azure-sql-server-using-active-directory-integrated-authentica – Dan Block Nov 10 '22 at 22:29
  • @Dan Block: Nope, it gives the same error. – Lily Nov 10 '22 at 22:36
  • have you found a solution? I have the same problem, went through the official MS guide, and did all the obvious steps, but still no luck... – Lukas K Feb 10 '23 at 15:37

1 Answers1

0

This can happen if the user account is a guest account in the tenant or is the wrong type of account (personal account). You should be able to resolve this by using an Azure AD account that is a member of the tenant with an organizational user name (myuser@tenant.onmicrosoft.com) and not a Microsoft/live account.

Marilee Turscak - MSFT
  • 7,367
  • 3
  • 18
  • 28