Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

C# Entity Framework Basics Introducing Entity Framework Using the Context

Ezequiel Hurt
Ezequiel Hurt
8,061 Points

SQL Unhandled Exception

I was following the example. Every was fine, but when I build and run the project, I have an exception.

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll

Additional information: CREATE DATABASE permission denied in database 'master'.

2 Answers

James Churchill
STAFF
James Churchill
Treehouse Teacher

Ezequiel,

Sounds like your user account doesn't have the correct permissions to create a new database. What does your development environment look like? What versions of Visual Studio do you have installed? Have you installed a version of SQL Server as well?

Thanks ~James

Ezequiel Hurt
Ezequiel Hurt
8,061 Points

James, thanks for your answer. I don't know why is trying to connect to master db. I continued the course and declare the string connection on the app.config and the problem was solved automatically.

Best regards, Ezequiel.

James Churchill
James Churchill
Treehouse Teacher

Connecting to the master database is necessary to do in order to create a new database. When you explicitly provide a database connection string, are you specifying LocalDB to be your database server? If so, my guess is that you might have SQL Server Express installed (in addition to LocalDB) and your Windows user account isn't assigned to the correct SQL Server group so you can't access Express' master database.

Ezequiel Hurt
Ezequiel Hurt
8,061 Points

Hi James, thanks for your answer. It's like you guess. I saw on the SQL Server Explorer the instance of SQL EXPRESS, and the local DB. I went to Tools -> Options -> Database Tools -> Data Connection and on field SQL Server Instance Name I deleted the localDB and left in blank. Then I add the string to app.config. I think with the string I'm forcing visual studio to use the LocalDB. For the time being, its ok.

Best regards.- Ezequiel