0

I am using the following connection string (from the "Show database connection strings" option in the Azure portal") to connect to an Azure SQL database;

services.AddDbContext<PwttContext>(options => options.UseSqlServer("Server=tcp:<serverName>.database.windows.net,1433;Initial Catalog=<databaseName>;Persist Security Info=False;User ID=<userId@organisation.com>;Password=<password>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Authentication='Active Directory Password';"));

However when I run a Update-Database in the Package Manager console I get the following error;

System.ArgumentException: Keyword not supported: 'authentication'

I have tried Authentication=""Active Directory Password"" and Authentication="\Active Directory Password\" to escape the quote characters with no success.

If I remove the Authentication key word and value and use;

services.AddDbContext<PwttContext>(options => options.UseSqlServer("Server=tcp:<serverName>.database.windows.net,1433;Initial Catalog=<databaseName>;Persist Security Info=False;User ID=<userId@organisation.com>;Password=<password>;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;"));

I then get the error System.Data.SqlClient.SqlException (0x80131904): Cannot open server "organisation.com" requested by the login. The login failed

Andrew Williamson
  • 8,299
  • 3
  • 34
  • 62
Ray
  • 342
  • 5
  • 15

1 Answers1

0

Use the admin user of your SQL Azure database on the following connection string of the appsettings.json. If you don't know the Admin password, reset the password using instructions provided in this article.

{
"Logging": {
    "IncludeScopes": false,
    "LogLevel": {
    "Default": "Warning"
}
},
"ConnectionStrings": {
    "Development": "Server=tcp:YourServername.database.windows.net,1433;Initial Catalog=TheNameOfTheDatabase;Persist Security Info=False;User ID=User;Password=Password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
}
}

The startup.cs should look like below:

public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddMvc();

        // Add database services.
        services.AddDbContext<ApplicationContext>(options => 
            options.UseSqlServer(Configuration.GetConnectionString("Development")));
    }

Specify the database name below:

ApplicationContext.cs. 
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer("Data Source=DatabaseNameHere");
    }
Alberto Morillo
  • 13,893
  • 2
  • 24
  • 30
  • This completely defeats the purpose of using Active Directory authentication, the whole point of this is so that connection credentials are NOT stored in the connection string due to security. The fact that this error is being thrown shows an underlying problem, not that the user is using the wrong connection string. See here >> https://stackoverflow.com/questions/42088766/ado-net-azure-ad-error-keyword-not-supported-authentication – ataraxia Aug 23 '19 at 22:18