gpt4 book ai didi

entity-framework - 从数据库获取提供者信息时出错

转载 作者:行者123 更新时间:2023-12-04 04:06:46 28 4
gpt4 key购买 nike

得到错误:

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)



尝试执行 Add-Migration 时遇到相同的错误

这是我的连接字符串,我需要访问我的本地 SQL 服务器而不是 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。同样的问题。

我尝试了连接字符串中数据源的许多变体,但都不起作用,以下是一些示例:
  • 本地主机\MSSQLSERVER
  • .\MSSQLSERVER
  • //本地主机\MSSQLSERVER
  • (本地)\MSSQLSERVER
  • 127.0.0.1\MSSQLSERVER

  • 如果我这样做 .\SQLEXPRESS 它可以工作。

    最佳答案

    设法解决了它。

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

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

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

    执行了 Update-Database -TargetMigration:$InitialDatabase这不起作用,因为它说仍有待定的更改。

    所以我表演了
    System.Data.Entity.Database.SetInitializer(     
    new System.Data
    .Entity
    .DropCreateDatabaseIfModelChanges<ReaderInsightDbContext>());

    在 global.asax 文件中。

    把它注释掉,所以它不会再运行了。然后我做了一个 Add-Migration Init,它为整个数据库重新创建了脚本,当我运行 Update-Database 时,它​​就像一个魅力。

    关于entity-framework - 从数据库获取提供者信息时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12271867/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com