Not able to connect via authentication type ActiveDirectoryServicePrincipal

Shruti Chandra 0 Reputation points
2024-04-17T06:22:42.0933333+00:00

I am trying to connect through connection string and auth type ActiveDirectoryServicePrincipal but it is failing with error - Failed to parse the connection string. No connection info returned.

This is the connection string i am using -

jdbc:sqlserver://<server>:1433;database=<db>;encrypt=true;trustServerCertificate=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;Authentication=ActiveDirectoryServicePrincipal;user=<spnID>;password=<spnSecret>

i tried using AADSecurePrincipalId and AADSecurePrincipalSecret also but still same error

doc - https://learn.microsoft.com/en-us/sql/connect/jdbc/connecting-using-azure-active-directory-authentication?view=sql-server-ver16#connect-using-activedirectoryserviceprincipal-authentication-mode

please help.

Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. ShaktiSingh-MSFT 13,426 Reputation points Microsoft Employee
    2024-04-18T03:51:38.7833333+00:00

    Hi Shruti Chandra •,

    Welcome to Microsoft Q&A forum.

    As I understand, you are not able to connect via authentication type ActiveDirectoryServicePrincipal to Azure SQL Database.

    In Active Directory Service Principal authentication mode, the client application can connect to Azure SQL data sources by providing the client ID and secret of a service principal identity. Service principal authentication involves:

    1. Setting up an app registration with a secret.
    2. Granting permissions to the app in the Azure SQL Database instance.
    3. Connecting with the correct credential.

    The following example shows how to use Active Directory Service Principal authentication.

    // Use your own server, database, app ID, and secret.

    string ConnectionString = @"Server=demo.database.windows.net; Authentication=Active Directory Service Principal; Encrypt=True; Database=testdb; User Id=AppId; Password=secret";

    using (SqlConnection conn = new SqlConnection(ConnectionString)) {

    conn.Open(); }

    Could you please also ensure you have required dependent libraries from the Client setup requirements?

    Awaiting your reply, thanks.

    0 comments No comments