Code First Update-Database Keyword Not Supported

azure-sql-database connection-string entity-framework-core

Question

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

1
0
5/29/2018 1:56:06 AM

Popular Answer

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");
    }
0
5/29/2018 3:03:07 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow