本文介绍了从数据库获取提供者信息时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获取错误:

在尝试执行添加迁移

这是我的连接字符串,我需要访问本地SQL服务器而不是SQLEXPRESS。 / p>

Here is my connection string, I need to access my local SQL server and NOT SQLEXPRESS.

  <connectionStrings>
    <add name="ReaderInsightDbContext" 
         connectionString="data source=localhost\MSSQLSERVER;
                         initial catalog=ReaderInsight;Integrated Security=True" 
         providerName="System.Data.SqlClient" />
  </connectionStrings>

我的数据库位于:

C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA

所以我的实例是MSSQLSERVER。不知道发生了什么。最初效果很好,但是在我更改代码以使用UOW模式之后,这种情况正在发生。我也从EF 4.3升级到EF5。相同的问题。

So my instance is MSSQLSERVER. Not sure what is going on. It first worked just fine, but after I changed my code to use the UOW pattern, this is happening. I also upgraded from EF 4.3 to EF5. Same issue.

我尝试了连接字符串中数据源的多种变体,没有任何作用,下面是一些示例:

I tried many variations of the data source in the connection string, none work, here are some examples:


  • localhost\MSSQLSERVER

  • .\MSSQLSERVER

  • //本地主机\MSSQLSERVER

  • (本地)\MSSQLSERVER

  • 127.0.0.1\MSSQLSERVER

  • localhost\MSSQLSERVER
  • .\MSSQLSERVER
  • //localhost\MSSQLSERVER
  • (local)\MSSQLSERVER
  • 127.0.0.1\MSSQLSERVER

如果我这样做。SQLEXPRESS可以正常工作。

If I do .\SQLEXPRESS it works.

推荐答案

设法解决它。

手动删除迁移文件的底线会导致问题。

Bottom line manually deleting the migration files causes issues.

请确保我的连接字符串如下所示:

Made sure my connection string looks like so:

  <connectionStrings>
    <add name="ReaderInsightDbContext" 
     connectionString=
     "Data Source=(local);Initial Catalog=ReaderInsight;Integrated Security=True"
     providerName="System.Data.SqlClient" />
  </connectionStrings>

执行 Update-Database -TargetMigration:$ InitialDatabase 无效,因为它说仍有待更改。

Performed an Update-Database -TargetMigration:$InitialDatabase which did not work as it said there is still pending changes.

所以我执行了

System.Data.Entity.Database.SetInitializer(     
  new System.Data
            .Entity
            .DropCreateDatabaseIfModelChanges<ReaderInsightDbContext>()); 

在global.asax文件中。

in the global.asax file.

对其进行了注释,因此它不会再次运行。然后,我执行了Add-Migration Init,它为整个数据库重新创建了脚本,当我运行Update-Database时,它就像一个魅力一样。

Commented it out, so it wont run again. I then did a Add-Migration Init and it recreated the script for the entire DB and when I ran Update-Database worked like a charm.

这篇关于从数据库获取提供者信息时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 20:47