If a customer tries to publish a web application with .NET – Entity Framework, that use SQL 2016, it will show this error:
System.Data.SqlClient.SqlException: CREATE DATABASE permission denied in database 'master'.
Why this happen
Our Hosting is a Shared Hosting, so every part of Environment has a Security Contest that not permit a customer to see content or databases of another customer.
In this specific case, every SQL Login have a specific DENY in the permission VIEW ANY DATABASE
This DENY not permit to see other db except master and tempdb.
So when you try to start application, Entityframework do a query to table sysdatabases to see if db exist, can’t see db, so try to recreate it from Zero (our DBA permission doesn’t permit to create a new db), web page show error.
This didn’t happen with SQL 2014 because there was a bug where a Login with DENY in VIEW ANY DATABASE, can see metadata of all DATABASES in table sysdatabases of db Master
This bug (that was there from SQL 2005, in the years has become a feature) is fixed in SQL 2016.
To use EntityFramework in our Shared Hosting, you have to do:
In this case when application starts, it will not check if the db exists but will assume that there is.
Remove DENY in VIEW ANY DATABASE permission in the SQL Login.
We can't apply this in a shared hosting enviroment.
Contatta i nostri esperti, sono a tua disposizione.Contattaci