I am getting below error while connecting to Azure SQL from App Service on Azure. Using ASP.NET WEB API not .net core.
Exception Details: System.Data.SqlClient.SqlException: Login failed for user ''. [InvalidOperationException: This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection.]
Web.config -
connectionString="Server=tcp:xxxxx;Database=xxx;" providerName="System.Data.SqlClient"/>
TestDBContext.cs -
public TestDBContext() : base("name=" + ConfigurationManager.AppSettings["ContextName"]) {
var conn = (System.Data.SqlClient.SqlConnection)Database.Connection;
var credential = new Azure.Identity.DefaultAzureCredential(new DefaultAzureCredentialOptions { ManagedIdentityClientId = "xxxxxxxxxxxx" });
var token = credential.GetToken(new Azure.Core.TokenRequestContext(new[] { "https://database.windows.net/.default" }));
conn.AccessToken = token.Token;
}






Persist Security Info = True;to your connection string.Integrity security=true;