CREATE DATABASE is permitted in the "master" database. MVC EF 4.1 Codefirst Getting Started

I checked here and on the internet without an answer. How do I make this work? I am using discountasp.net SQL, so is it a third-party setup to make it work?

+4
source share
2 answers

The following blog explains this well. If you did not specify a connection string in your web.config than EF, CodeFirst will try to create a database on your local SQLExpress instance. Otherwise, you can set the intent by assigning a named string connnection through the public constructor of the context of your objects, inheriting from the base constructor.

http://blogs.msdn.com/b/adonet/archive/2011/01/27/using-dbcontext-in-ef-feature-ctp5-part-2-connections-and-models.aspx

public class UnicornsContext : DbContext { public UnicornsContext() : base("UnicornsCEDatabase") { } } 

In any case, you will need to make sure that your account has appropriate access to the SQL (Express) server to create a new database.

+5
source

The user in the connection string used to access the database does not have the right to create the database, so an exception is thrown. Try changing the user or granting him access rights.

+1
source

Source: https://habr.com/ru/post/1347615/


All Articles