简体   繁体   English

无法将文件“ <>。mdf”附加为数据库“ <>”

[英]Cannot attach the file '<>.mdf' as database '<>'

I'm working on a project with different implementations of DbContext. 我正在使用DbContext的不同实现的项目。 Using EF code first, I generate migration : 首先使用EF代码,我会生成迁移:

Enable-Migrations -ContextTypeName <> -Force
Add-Migration <>_DB_v1.0
Update-Database -Verbose

The update always tries to attach the *.mdf file but no file is ever genrated in local, and I'm working on a distant SQL Server (Distant virtual DB) the Update-Script option successfully generates the SQL file and well executed on the Db, but I always get error to execute last update before going on new migration. 更新始终尝试附加* .mdf文件,但从未在本地生成文件,并且我正在使用远程SQL Server(远程虚拟DB), Update-Script选项成功生成了SQL文件并在db,但是在进行新迁移之前,执行上一次更新总是出错。

Could any body help ? 有身体可以帮助吗?

Project is in .net 4.6, and using EF 6.0. 项目位于.net 4.6中,并使用EF 6.0。

Sorry not able to paste code for confidentiality. 抱歉,无法粘贴代码以确保机密性。 I may ensure that All connection string, project conf. 我可以确保所有连接字符串,项目为conf。 and so are perfectly set. 这样就完美了。

Please ensure that migration history table in the Db and Migrations files in your Solution are match. 请确保Db中的迁移历史表与解决方案中的迁移文件匹配。

I think you miss some migration. 我想您会错过一些迁移。

I found the error reason: 1- Indicate explicitly the providerName="System.Data.SqlClient" in the connectionStrings definition 我发现了错误原因:1-在connectionStrings定义中明确指出providerName =“ System.Data.SqlClient”

2- Executing the migration, specify the -ConnectionStringName, even if the name displaed in the console seems to be OK. 2-执行迁移,即使在控制台中显示的名称似乎正常,也请指定-ConnectionStringName。

Add-Migration DB_vX.x -ConnectionStringName XXX_Database update-database -Verbose -Script -ConnectionStringName XXX_Database 添加迁移DB_vX.x -ConnectionStringName XXX_Database更新数据库-详细-Script -ConnectionStringName XXX_Database

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM