I have a SQL Server A with DatabaseA, and I created 5 views based on tables from SQL Server B DatabaseB.
- DatabaseA: login is userA, pwd: userA
- DatabaseB: login is userB, pwd: userB
In the ASP.NET Core project startup, I have this code:
services.AddDbContext<DatabaseContext>(options => options.UseSqlServer(Configuration.GetConnectionString("sqlConnection"), b => b.MigrationsAssembly("API")));
and this connection string in appsettings.json:
"ConnectionStrings": {
"sqlConnection": "Server=TESTING\\SQLEXPRESS;Database=DatabaseA;User ID=userA;Password=userA;"
}
I get the error when I need to access the view
The server principal "userA" is not able to access the database "DatabaseB" under the current security context
How can I solve this?