Code First Update-Database Keyword Not Supported

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

azure-sql-database
entity-framework-core
connection-string
asked on Stack Overflow May 29, 2018 by Ray • edited May 29, 2018 by Andrew Williamson

1 Answer

1

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");
    }
answered on Stack Overflow May 29, 2018 by Alberto Morillo

User contributions licensed under CC BY-SA 3.0