【问题标题】:MVC4 Is my Connection String to SQL Server 2014 correctMVC4 我到 SQL Server 2014 的连接字符串是否正确
【发布时间】:2016-03-01 19:02:02
【问题描述】:

我正在使用 Visual Studio 2012 for Web 并且正在编写 MVC 应用程序。默认情况下,它使用 localDB,但我希望它在 SQL Server 上。我已经安装了 SQL Server 2014,我的服务器名称是 C0208\SQLEXPRESS。

C0208 是我的电脑名

命名实例:SQLEXPRESS

InstanceID:SQLEXPRESS

这是我到 localdb 的连接字符串

<add name="IssueContext" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=RecreationalServicesTicketingSystem;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\RecreationalServicesTicketingSystem.mdf" providerName="System.Data.SqlClient" />

我试过用这个连接字符串,不知道对不对

<add name="IssueContext" providerName="System.Data.SqlClient" connectionString="Data Source=C0208\SQLEXPRESS;User Id=C0208;Initial Catalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True" />

【问题讨论】:

  • 我可以进入索引页面,但它不允许我使用其他选项卡 所以?我收到此错误Unable to update database to match the current model because there are pending changes and automatic migration is disabled. Either write the pending model changes to a code-based migration or enable automatic migration. Set DbMigrationsConfiguration.AutomaticMigrationsEnabled to true to enable automatic migration.
  • @David 我有 2 个反复出现的错误。我上面提到的一个和另一个关于无法找到与数据库的连接的问题。

标签: sql-server asp.net-mvc-4 database-connection connection-string


【解决方案1】:

这看起来更像是实体框架问题,而不是 SQL 连接字符串。只需检查您是否在任何地方都更新了连接字符串。 (app.config)。 要启用数据迁移,您必须在 Package Manager Console 中运行以下命令。

enable-migrations

如果出现错误,请先尝试以下命令

add-migration projectName

更多详情请查看this link

【讨论】:

    猜你喜欢
    • 2016-03-27
    • 1970-01-01
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多