代码优先创建数据库 Entity Framework 失败

Failed to create database Entity Framework code-first

我正在尝试使用 Entity Framework 和 code-first 方法创建数据库,但创建数据库失败并出现以下异常:

Unhandled Exception: System.Data.DataException:
An exception occurred while initializing the database. See the InnerException for details.

System.Data.Entity.Core.EntityException: The underlying provider failed on Open.

System.Data.SqlClient.SqlException: Cannot open database "X.Xcontext" requested by the login. The login failed. Login failed for user 'This-PC\ME'.

知道如何解决这个问题吗?

您的用户没有创建数据库的权限,您需要联系您的 DBA 以获得权​​限,或者根据您的工作地点,您需要创建一个票证才能让某人为您创建数据库。

好吧,当我刚重命名我的 DbContext 时问题就解决了。不知道为什么,但它对我有用!