简体   繁体   中英

“Keyword not supported: authentication” when using Active Directory Password against AAD in Azure Web App

I'm have an Azure Web App where I've set the connection string to point to an Azure SQL DB. I'd prefer to use an Azure Active Directory username/password for authentication so I used the following connection string:

Server=tcp:mydb.database.windows.net,1433;Initial Catalog=mytable;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication="Active Directory Password";

This causes my app to fail with the error:

Keyword not supported: 'authentication'

If I use the SQL Authentication (ie remove the Authentication="Active Directory Password" and change User ID and Password to an appropriate SQL username and password), everything works as expected.

Is it possible to use Active Directory Password with an Azure Web App connection string in order to use an AAD username/password to connect to an Azure SQL Db?

Please change the connection string as shown below:

string ConnectionString =
@"Data Source=n9lxnyuzhv.database.windows.net; Authentication=Active Directory Password; Initial Catalog=testdb;  UID=bob@contoso.onmicrosoft.com; PWD=MyPassWord!";
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();

Another option:

string ConnectionString =
@"Data Source=n9lxnyuzhv.database.windows.net; Authentication=Active Directory Integrated; Initial Catalog=testdb;";
SqlConnection conn = new SqlConnection(ConnectionString);
conn.Open();

Please note the text following the Authentication keyword.

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