从数据库获取提供者信息时发生错误 [英] An error occurred while getting provider information from the database

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

问题描述

获取错误:


System.Data.ProviderIncompatibleException:从数据库获取提供者信息时发生错误。这可能是由于Entity Framework使用了错误的连接字符串引起的。

检查内部异常以获取详细信息,并确保连接字符串正确。

---> System.Data。 ProviderIncompatibleException:提供程序未返回ProviderManifestToken字符串。

---> System.Data.SqlClient.SqlException:建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (提供者:SQL网络接口,错误:25-连接字符串无效)

System.Data.ProviderIncompatibleException: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string.
Check the inner exceptions for details and ensure that the connection string is correct.
---> System.Data.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.
---> System.Data.SqlClient.SqlException: 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: 25 - Connection string is not valid)

在尝试执行添加迁移

这是我的连接字符串,我需要访问本地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.

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

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