代码优先迁移中update-database命令中的错误 [英] Error in update-database command in code first migration

查看:642
本文介绍了代码优先迁移中update-database命令中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在WPF中处理桌面应用程序,并使用 LocalDB 创建SqlRepository来存储数据.我正在使用以下工具

I am working on Desktop application in WPF and creating SqlRepository with LocalDB to store data. I am using following tools

  • 带有更新2的Visual Studio 2013社区
  • 用于代码优先迁移的实体框架6.1.2

我已经使用Microsoft SQL Server数据库文件(SqlClient)配置创建了本地数据库.成功创建的数据库及其以下是从Sql获取的连接字符串

I have created local database with Microsoft SQL Server Database File (SqlClient) configuration. Database created successfully and below is connection string fetched from Sql

Data Source=(LocalDB)\v11.0;Initial Catalog=D:\USERS\USERNAME\DOCUMENTS\TestDatabase\testdb.MDF;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False

我在app.config中使用了相同的连接字符串.我可以在Visual Studio的SQL Server数据库浏览器中查看数据库对象.但是在Nuget软件包管理器控制台中运行update-database命令时,出现以下错误:

I am using same connection string in app.config. I can view database object in SQL Server Database explorer in Visual Studio. But when run update-database command in Nuget package manager console, I am getting below error:

与网络相关或特定于实例的错误发生在 建立与SQL Server的连接.找不到服务器或 无法访问.验证实例名称正确,并且 SQL Server配置为允许远程连接. (提供者:SQL 网络接口,错误:26-错误定位服务器/实例 已指定)

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

推荐答案

当我将启动项目"从另一个模块更改为包含对解决方案中所有其他项目的引用的模块时,我遇到了类似的问题并将其修复. 右键单击模块>>单击设置为启动项目"

I had similar problem and fixed it when I changed the "start-up project" from another module to the module containing references to all other projects in the solution. Right-click module >> click "Set as StartUp Project"

这篇关于代码优先迁移中update-database命令中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆