SQL Server EF 6 Code First : "CREATE DATABASE permission denied in database 'master'." on existing database

omjgkv6w  于 12个月前  发布在  其他
关注(0)|答案(2)|浏览(100)

I'm facing some troubles with my EF Model.

History: When my app was released in production a few years ago, my EF model was created via the Model First (edmx) technique. I works well on my production server with my SQL SERVER db.

Now I'm doing some improvements on my app, and I decided to leave the Model First technique to go on the Code first technique. It's working great on my localhost, but when I release my new app version on my production server and when my app tries to use the model I got this message:
CREATE DATABASE permission denied in database 'master'.

But I don't get it... My database still exists on my production server (since several years). Why does EF would like to create something? What can be wrong?

Thanks in advance for your answers.

EDIT:

Summary:

  • For the same database on the same server
  • For the same connectionstring
  • For the same EF version (6)
  • App with Model First works without problem
  • App with Code First throw exception CREATE DATABASE permission denied in database 'master'.

BUT the database already exists. Why this error? Why does the code first version tries to create a database?

3qpi33ja

3qpi33ja1#

Check this

https://stackoverflow.com/a/19198471/8186328

Be sure that your connection string name is the same that the base constructor of your dbContext

ny6fqffe

ny6fqffe2#

It doesn't see the target database and so it's trying to create it, even though (to you) it may be there.

When this happened to me, I realized the connection string was wrong. There are two places to double-check this:

  1. The connection string name in your model class (typically in the constructor).
  2. The corresponding connection string, i.e., server and database name, in the .config file.

相关问题