Asp mvc 3 noobie: CREATE DATABASE permission on the 'master' database is allowed

I am asp mvc 3 noobie. I have done some tutorials and am now ready to continue learning while trying to create a site.

In all tutorials, you connect to the SQL CE or SQL Express database. But I want my site to create a database on the sql server.

I created a database on my network server, which I will call MyDB. Then I installed the connection string in my web configuration file as follows:

add name="ApplicationServices" connectionString="Data Source=Server\ServerInstance;Initial Catalog=MyDB;Integrated Security=True" providerName="System.Data.SqlClient" 

I created models and a forest controller.

I created a simple DataBaseContext as follows:

 Imports System.Data.Entity Public Class DatabaseContext Inherits DbContext Public Property Employee As DbSet(Of Employee) Public Property AnnualLeave As DbSet(Of AnnualLeave) End Class 

But when I find the following line in the forest controller, I get an error:

  Function Index() As ViewResult Return View(db.Employee.ToList()) //CREATE DATABASE permission denied in database 'master'`. End Function 
  • Should I fix this by changing permissions in the MyDB database? Is this a problem with SQL Server permissions? I am confused why I am getting a database creation error because the database already exists.
  • I get this b / c error Have I already created the database? Are scaffolding somehow creating a database?
+4
source share
3 answers

It looks like he is trying to create a new database using an error message. I assume that you first use the EF code with your project and use its features to create your database. Check your EF context setting to make sure it uses your connection string.

The connection string or its name can be passed to the DbContext constructor. If you use the default constructor, it looks for a connection string with the same name as the name of your derived context class. Basically, make sure your connection string has the same name as your dbcontext derived class, and it should find it.

See this post for more information.

+4
source

1. You need to set the IIS application pool identifier to ASP.NET integration mode.

2. Add the login to SQL Server for IIS APPPOOL \ ASP.NET.

3. In SQL Server, set up the dbcreator role to access IIS APP POOL.

+3
source

USE master; EXECUTE sp_addsrvrolemember @loginame = N'YourAppUserLogin ', @rolename = N'dbcreator';

0
source

All Articles