Is there an existing issue for this?
Library Version
6.0.16
What happened?
Hi,
I just managed to get dbup working with a connection string to an Azure SQL database using ActiveDirectoryManagedIdentity authentication.
There are 2 things I want to point out.
1. Checking if the database exists, still does not work:
varsqlBuilder=newSqlConnectionStringBuilder(options.ConnectionString);EnsureDatabase.For.SqlDatabase(sqlBuilder.ConnectionString);
I get the same exception as if I would use the DeployChanges.To.SqlDatabase() to get a builder:
Unhandled exception. Microsoft.Data.SqlClient.SqlException (0x80131904): ManagedIdentityCredential authentication unavailable. The requested identity has not been assigned to this resource.
Looking at the internal code, it sets up a SqlConnection which is different from the connection set up by the AzureSqlConnectionManager.
For reference, my full code to check database existance and return a builder is
staticUpgradeEngineBuilderGetBuilder(Optionsoptions){varsqlBuilder=newSqlConnectionStringBuilder(options.ConnectionString);if(sqlBuilder.DataSource.Contains("database.windows.net")&&sqlBuilder.Authentication==SqlAuthenticationMethod.ActiveDirectoryManagedIdentity)//Azure SQL with Managed Identity authentication{//Checking if database exists with EnsureDatabase does not work Azure Managed Identity connectionEnsureDatabase.For.SqlDatabase(sqlBuilder.ConnectionString,DbUp.SqlServer.AzureDatabaseEdition.Basic);sqlBuilder.Authentication=SqlAuthenticationMethod.NotSpecified;//Remove authentication method since AzureSqlDatabaseWithIntegratedSecurity sets an access tokenreturnDeployChanges.To.AzureSqlDatabaseWithIntegratedSecurity(sqlBuilder.ConnectionString);}else{EnsureDatabase.For.SqlDatabase(sqlBuilder.ConnectionString);returnDeployChanges.To.SqlDatabase(sqlBuilder.ConnectionString);}}2. The authentication part
A second thing I want to point out is that I manually need to remove the Authentication part of the connection string by setting it to NotSpecified. Is it possible to let the AzureSqlConnectionManager perform this action? If I don't clear the Authentication part, I get the exception:
System.InvalidOperationException: Cannot set the AccessToken property if 'Authentication' has been specified in the connection string.
Thanks!
Is there an existing issue for this?
Library Version
6.0.16
What happened?
Hi,
I just managed to get dbup working with a connection string to an Azure SQL database using ActiveDirectoryManagedIdentity authentication.
There are 2 things I want to point out.
1. Checking if the database exists, still does not work:
I get the same exception as if I would use the
DeployChanges.To.SqlDatabase()to get a builder:Unhandled exception. Microsoft.Data.SqlClient.SqlException (0x80131904): ManagedIdentityCredential authentication unavailable. The requested identity has not been assigned to this resource.Looking at the internal code, it sets up a SqlConnection which is different from the connection set up by the AzureSqlConnectionManager.
For reference, my full code to check database existance and return a builder is
2. The authentication part
A second thing I want to point out is that I manually need to remove the
Authenticationpart of the connection string by setting it toNotSpecified. Is it possible to let the AzureSqlConnectionManager perform this action? If I don't clear theAuthenticationpart, I get the exception:System.InvalidOperationException: Cannot set the AccessToken property if 'Authentication' has been specified in the connection string.Thanks!