Reputation: 2108
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
?
Upvotes: 3
Views: 1630
Reputation: 852
You need to give your account a global server permission to create database on the server.
Upvotes: 3