Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - CREATE DATABASE permission denied in database 'master' (EF - code first)

I've seen some of the answers in here, but nothing helped resolving the problem.

I'm following Microsoft ITAcademy tutorial on MVC Jumpstart and they teach by an example that uses EF Code-First approach.

When I'm running the application, I'm getting an error:

CREATE DATABASE permission denied in database 'master'

This is my connection string:

<add name="DefaultConnection" 
     connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-Conference-20150930151714;Integrated Security=true" 
     providerName="System.Data.SqlClient" />`

I do not post all the code in here, since it is a work through Microsoft tutorial line by line.

It fails when I call one of the controller that is supposed to have data retrieved from the database:

public ActionResult Index()
{
    return View(db.Speakers.ToList());//fails here with described exception
}

This is how Database is initialized in Global.asax.cs:

using System.Data.Entity;    
public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        Database.SetInitializer<ConferenceContext>(new ConferenceContextInitializer());
        //the rest of code....// 
    }
}

This is ConferenceContext class:

using System.Data.Entity;
public class ConferenceContext : DbContext
{
    //public ConferenceContext() : base("name = DefaultConnection") { }
    public DbSet<Session> Sessions { get; set; }
    public DbSet<Speaker> Speakers { get; set; }
}

This is a piece of code for adding dummy data to Database:

public class ConferenceContextInitializer : DropCreateDatabaseAlways<ConferenceContext>
{
    protected override void Seed(ConferenceContext context)
    {
        context.Sessions.Add(
            new Session()
            {
                Title = "I want Spaghetti",
                Abstract = "The life and times of spaghetti lover",
                Speaker = context.Speakers.Add(
                    new Speaker()
                    {
                        Name = "John Doe",
                        EmailAddress = "[email protected]"
                    })
            });
        context.SaveChanges();
    }
}

Can you explain me where the database is supposed to be created?

Should I have special permissions on my SQL Server for that or it is just enough to create a database in App_Data folder?

Will I be able to do create Database at all on my work PC?

like image 788
gene Avatar asked Dec 10 '25 19:12

gene


1 Answers

You need to give your account a global server permission to create database on the server.

like image 166
Yoky Avatar answered Dec 13 '25 08:12

Yoky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!