1

I saw that this is common problem, however did not manage to solve it yet.

It's about example from http://www.w3schools.com/ASPnet/mvc_models.asp

This example uses SQL Server Compact Local Database (SDF), but I need it with SQL Server Database File (MDF).

I got following error:

CREATE DATABASE permission denied in database 'master'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: CREATE DATABASE permission denied in database 'master'.

This is connectionString in my Web.config file:

  <add
    providerName="System.Data.SqlClient"
    connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|Movies.mdf;InitialCatalog=DatabaseName;MultipleActiveResultSets=True;Integrated Security=True;" name="MovieDBContext"  />

Can you help me how to solve this?

2 Answers 2

1

Your connection string specifies both a connection to the DatabaseName database in LocalDb and a filename. Attachable databases are a feature of SQL Express, not LocalDB so the AttachDbFileName property is ignored.

To attach to a file for single use you should use .\SQLExpress as the Data Source, eg:

Data Source=.\SQLExpress;AttachDbFilename=|DataDirectory|Movies.mdf;...
Sign up to request clarification or add additional context in comments.

4 Comments

Nope, still same problem
Using which connection string?
Is the database file already attached to SQL Express? Another issue may be that the application pool's account may not have permission to connect to SQL Express
using this one: <connectionStrings><add providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLExpress;AttachDbFilename=|DataDirectory|Movies.mdf;InitialCatalog=DatabaseName;MultipleActiveResultSets=True;Integrated Security=True;" name="MovieDBContext" /></connectionStrings>
0

Try this in your dbcontext class constructor:

public class MovieDBContext : DbContext
{
    public MovieDBContext() : base(System.Configuration.ConfigurationManager
        .ConnectionStrings["MovieDBContext"].ConnectionString)
    {
    }

    public DbSet<Movie> Movies { get; set; }
}

1 Comment

This isn't related to the question (the OP didn't even mention EF) and it will result in the same error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.