I am encountering an issue where a SQL database that I deleted reappeared and caused unexpected high costs on our Azure account.
Background:
Issue:
My expected behavior:
Questions:
Relevant Code:
Program.cs
var sqlConBuilder = new SqlConnectionStringBuilder();
sqlConBuilder.ConnectionString = builder.Configuration.GetConnectionString("SQLDbConnection");
builder.Services.AddDbContext<AppDbContext>(opt => opt.UseSqlServer(sqlConBuilder.ConnectionString));
builder.Services.AddScoped<IUsageRepo, UsageRepo>();
UsageRepo.cs
public class UsageRepo : IUsageRepo
{
private readonly AppDbContext _context;
public UsageRepo(AppDbContext context)
{
_context = context;
}
public async Task CreateUsage(Usage usage)
{
if (usage == null)
{
throw new ArgumentNullException(nameof(usage));
}
await _context.AddAsync(usage);
}
// Other methods...
}
Screenshot of Azure Monitor for deletion logs (There is no log for SQL Database created, after I removed it I can see the database update log with the same database name):
Thank you for your support.
Best regards,
Mert
First of, I'd try to open a Billing Support case and try to lay down your situation to them. Eventually they will waive that costs. But they are the only instance which can help you in this case. Just go to the Azure Portal and Search for support (Billing Support doesn't require a Support Plan). https://azure.microsoft.com/en-us/support/create-ticket/
Coming to the code part, you are using entity framework. IF you run within the model creation Database.CreateIfNotExists()
, then indeed your code when you execute will try to create that Database.
I am not 100% sure what the default SKU is, but P1 might be exactly what you were experiencing, right?
When you use the connection string with the SQL Admin user you created on the SQL Server, this user will have the permissions to create a new Database, and as Azure SQL Server supports also Scaling Operations and Database creation via SQL commands it is totally possible to create a database without an action over the Azure Portal. And if I remember correctly, those are not reflected in the activity logs then. Only SQL audit (if enabled). In general it is advisable to use low-privileged users for data operations or use EntraID based authentication here.
TL;DR; expected behavior as your code was creating the database, and if it has the permissions to create one, it will do so.