I'm writing a web application that should use EF to manage a MS SQLExpress server database (the application is called RRDA).
The solution is divided into 3 projects: RRDA.Web (the web application), RRDA.Data (data models), RRDA.Core (base classes with data import plugins interface, validators etc).
I'm working with 'code-first' approach so I'm relating on EF tools to do initial creation of database and updates on the structure as long as I change the db structure itself (by code of course).
I defined a DBContext in RRDADbContext:
public class RRDADbContext(DbContextOptions options) : DbContext(options)
{
public DbSet ReportTypes { get; set; }
public DbSet ReportFiles { get; set; }
public DbSet ReportEntities { get; set; }
public DbSet ReportProperties { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity().HasIndex(p => new { p.Name, p.ReportEntityId });
// TODO: ...
}
}
And a DbContextFactory:
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
namespace RRDA.Data
{
public class RRDAContextFactory : IDesignTimeDbContextFactory
{
public RRDADbContext CreateDbContext(string[] args)
{
var optionsBuilder = new DbContextOptionsBuilder();
optionsBuilder.UseSqlServer("Server=.\\SQLEXPRESS;Database=RRDA.Db;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True;Integrated Security=True;Encrypt=True");
return new RRDADbContext(optionsBuilder.Options);
}
}
}
Now running the command:
dotnet ef migrations add InitialCreate -p RRDA.Data -s RRDA.Web
Works fine but:
dotnet ef database update -p RRDA.Data -s RRDA.Web
Ottengo il seguente errore:
CREATE DATABASE permission denied in database 'master'.
But as long as I can see I have all the priviledeges needed to create and alter database...
As a matter of fact I can 'manually' create the database from within VisualStudio but of course I cannot undestand if the ef tool is run with the same priviledeges... how can I check it?
BTW the exeptions message is quite long but it only adds the call stack without much more info...