Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EF-代码优先迁移:处理请求时数据库操作失败_C#_Entity Framework Core_Entity Framework Migrations_Asp.net Core 1.1 - Fatal编程技术网

C# EF-代码优先迁移:处理请求时数据库操作失败

C# EF-代码优先迁移:处理请求时数据库操作失败,c#,entity-framework-core,entity-framework-migrations,asp.net-core-1.1,C#,Entity Framework Core,Entity Framework Migrations,Asp.net Core 1.1,我将ASP.NET MVC Core 1.1.1项目及其SQL Server 2012db发布到了生产中。几天后,我备份了数据库并将其从生产服务器恢复到开发机器,并将其重新连接到我的VS2017开发项目。但当我尝试运行应用程序时,它会给我以下错误: A database operation failed while processing the request. InvalidOperationException: An exception has been raised that is li

我将ASP.NET MVC Core 1.1.1项目及其SQL Server 2012db发布到了生产中。几天后,我备份了数据库并将其从生产服务器恢复到开发机器,并将其重新连接到我的
VS2017
开发项目。但当我尝试运行应用程序时,它会给我以下错误:

A database operation failed while processing the request.

InvalidOperationException: An exception has been raised that is likely due to a transient failure. If you are connecting to a SQL Azure database consider using SqlAzureExecutionStrategy. 
SqlException: A connection was successfully established with the server, but then an error occurred during the login process. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) 
Win32Exception: No process is on the other end of the pipe 
我通过将同一个登录连接到
SSMS
检查了同一个数据库登录,它成功地连接到了数据库

此外,在上述错误消息的下方,还有以下消息,其中列出了项目进行的所有迁移:

Applying existing migrations for MyProjectContext may resolve this issue
There are migrations for MyProjectContext that have not been applied to the database

20161209232754_myFirstMigration
20170121191004_mySecondMigration
20170303172256_myThirdMigration
20170303172256_myFourthMigration

In Visual Studio, you can use the Package Manager Console to apply pending migrations to the database:

PM> Update-Database
Alternatively, you can apply pending migrations from a command prompt at your project directory:

> dotnet ef database update
注意

  • 开发计算机为
    Windows 10
    ,生产服务器为
    Windows Server 2012-R2
    。这两台机器都有相同版本的
    SQL Server 2012
  • 我已经验证了
    VS2017
    项目和数据库在本地开发机器上的迁移完全相同。部署到生产环境后,迁移从未在开发计算机上更改。当我从上面的错误消息中运行建议的命令
    PM>updatedatabase-context MyProjectContext
    时,我得到错误:
    CREATE Database permission denied in Database'master'

  • 我在过去也遇到过类似的情况,在数据库“master”消息中,
    CREATE DATABASE permission denied(创建数据库权限被拒绝)
    是由于完全忽略了连接字符串造成的(这听起来像是一件愚蠢的事情,但可能是由于多项目解决方案的错误配置造成的)


    检查您的配置字符串是否存在,是否具有您期望的名称,并且在运行时应用程序是否可见。如果您的实体框架代码位于类库中,并与主应用程序共享,请确保在应用迁移之前选择主应用程序作为启动项目,以便EF知道在何处查找App.config文件。

    我过去也遇到过类似的情况,其中,数据库“master”中的
    CREATE DATABASE permission denied(创建数据库权限被拒绝)
    消息是由于完全忽略了连接字符串造成的(这听起来像是一件愚蠢的事情,但可能是由于多项目解决方案的错误配置造成的)


    检查您的配置字符串是否存在,是否具有您期望的名称,并且在运行时应用程序是否可见。如果您的实体框架代码位于类库中,并且与主应用程序共享,请确保在应用迁移之前选择主应用程序作为启动项目,以便EF知道在何处查找App.config文件。

    就是这样。登录名/密码正确,但不是整个连接字符串。谢谢你给我指引了正确的方向,就这样。登录名/密码正确,但不是整个连接字符串。谢谢你给我指引了正确的方向。