SQL EF 4.1 异常“提供程序未返回 ProviderManifestToken 字符串”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5423278/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 09:50:44  来源:igfitidea点击:

EF 4.1 exception "The provider did not return a ProviderManifestToken string"

asp.netsqlentity

提问by bugnuker

I am trying to replicate an example found on MSDN. I am using ASP.NET and EF 4.1 (CTP?). I've used NuGet to install the EntityFramework package.

我正在尝试复制在 MSDN 上找到的示例。我正在使用 ASP.NET 和 EF 4.1(CTP?)。我已经使用 NuGet 来安装 EntityFramework 包。

I am getting this error: The provider did not return a ProviderManifestToken string... and the database is never created.

我收到此错误:The provider did not return a ProviderManifestToken string...并且从未创建数据库。

Here is my connection string:

这是我的连接字符串:

<add name="HospitalContext"
   connectionString=
   "data source=.\SQLExpress;initial catalog=NewTestDB;integrated security=True;"
   providerName="System.Data.SqlClient"/>

Here is my code:

这是我的代码:

var pat = new Patient { Name = "Shane123132524356436435234" };
db.Patients.Add(pat);

var labResult = new LabResult { Result = "bad", Patient = pat };

int recordAffected = db.SaveChanges();

Here is my context:

这是我的上下文:

public class HospitalContext : DbContext
{
    static HospitalContext()
    {
        Database.SetInitializer(new HostpitalContextInitializer());
    }

    public DbSet<Patient> Patients { get; set; }
    public DbSet<LabResult> LabResults { get; set; }
}

public class HostpitalContextInitializer :
             DropCreateDatabaseIfModelChanges<HospitalContext>
{
    protected override void Seed(HospitalContext context)
    {
        context.Patients.Add(new Patient { Name = "Fred Peters" });
        context.Patients.Add(new Patient { Name = "John Smith" });
        context.Patients.Add(new Patient { Name = "Karen Fredricks" });
    }
}

This is a fully patched SQL 2008 system, with VS 2010 SP1.

这是一个完全打补丁的 SQL 2008 系统,带有 VS 2010 SP1。

回答by junken

I was getting this error and tried a few of the earlier suggestions. Then I checked the Inner Exception and noticed I was getting a simple SQL login failure for the user. Just something else to check.

我收到此错误并尝试了一些早期的建议。然后我检查了内部异常并注意到我遇到了一个简单的用户 SQL 登录失败。只是其他要检查的东西。

回答by Preet Sangha

This can happen sometimes when you place the connection string within the app.config of the wrong project in Visual Studio.

当您将连接字符串放置在 Visual Studio 中错误项目的 app.config 中时,有时会发生这种情况。

For example, I got this problem in EF 4.1 (the released version) project + WCF Data Service project and I noticed that I didn't have a connection string specified in the Data Services Project, where it was being used.

例如,我在 EF 4.1(已发布版本)项目 + WCF 数据服务项目中遇到了这个问题,我注意到我没有在使用它的数据服务项目中指定连接字符串。

回答by Rakesh Singh

I was having same error, and actually it was login failed for the specified server. I removed "Integrated Security" attribute from the config connection string and it worked.

我遇到了同样的错误,实际上是指定服务器登录失败。我从配置连接字符串中删除了“集成安全性”属性并且它起作用了。

回答by toto123

I had the same problem, and I add the below code just after the instance of my context (onload by exemple)

我遇到了同样的问题,我在上下文实例之后添加了以下代码(例如加载)

context.Database.Connection.ConnectionString = @"Data Source=.\SQLExpress;Initial Catalog=Test;Integrated Security=True";

回答by xuvion

I had a similar issue with the MvcMusicStore app. I changed a line in the Web.config from "Instance=true" to "Instance=false". It sometimes works without this tweak but I don't know what causes the difference. Reading this http://msdn.microsoft.com/en-us/library/ms254504.aspxdidn't really help.

我在 MvcMusicStore 应用程序中遇到了类似的问题。我将 Web.config 中的一行从“Instance=true”更改为“Instance=false”。它有时在没有这种调整的情况下工作,但我不知道是什么导致了差异。阅读这个 http://msdn.microsoft.com/en-us/library/ms254504.aspx并没有真正的帮助。

回答by Telvin Nguyen

By some certain reason of permission, EF can not create database connection. I had faced the same problem all of one day. Finally I had tried following solution and it worked: a/ Open IIS (I'm using IIS 7) b/ Open advanced settings of appool which web site was using (Ex: DefaultAppPool) c/ Look at Process Model group, change Identity value to "Localsystem"

由于某种权限原因,EF 无法创建数据库连接。我一整天都面临着同样的问题。最后,我尝试了以下解决方案并且它起作用了:a/ 打开 IIS(我使用的是 IIS 7) b/ 打开网站正在使用的 appool 的高级设置(例如:DefaultAppPool) c/ 查看进程模型组,更改标识值到“本地系统”

Hope it work with you.

希望它和你一起工作。

回答by user1168945

I was just having the same problem...
the solution that worked for me was:
run the client network configuration tool (type cliconfg in Run)
and make sure TCP/IP is enabled..

我只是遇到了同样的问题……
对我
有用的解决方案是:运行客户端网络配置工具(在运行中键入 cliconfg)
并确保启用了 TCP/IP。

回答by Simon_Weaver

I finally cracked it - after a slight wild goose chase thinking it was due to permissions.

我终于破解了它 - 经过轻微的疯狂追逐,认为这是由于权限造成的。

Revelation: USE SQL PROFILER

启示:使用 SQL PROFILER

(Note: I recently downgraded from EF6 to EF5)

(注:我最近从 EF6 降级到 EF5)

Using SQL Profiler I quickly found the last SQL executed before the reported failure:

使用 SQL Profiler 我很快找到了在报告失败之前执行的最后一条 SQL:

SELECT TOP (1) 
[Project1].[C1] AS [C1], 
[Project1].[MigrationId] AS [MigrationId], 
[Project1].[Model] AS [Model]
FROM ( SELECT 
    [Extent1].[MigrationId] AS [MigrationId], 
    [Extent1].[Model] AS [Model], 
    1 AS [C1]
    FROM [dbo].[__MigrationHistory] AS [Extent1]
)  AS [Project1]
ORDER BY [Project1].[MigrationId] DESC

Well look at that - something to do with migrations. It's looking in __MigrationHistorytable - which I hadn't even realized it had created (I had already wiped out Migrations in my CSPROJ) and cleared that out.

看看那个 - 与迁移有关。它正在查看__MigrationHistory表格 - 我什至没有意识到它已经创建(我已经在我的 CSPROJ 中清除了迁移)并清除了它。

So I pull up the rows for that table and see that it is tied to a specific product version (v6).

因此,我拉出该表的行,并查看它与特定产品版本 (v6) 相关联。

enter image description here

在此处输入图片说明

I actually downgraded from EF6 (which I didn't intend to install in the first place) to EF5 (which is more compatible with scaffolding) and that when the problems began.

我实际上从 EF6(我一开始并不打算安装)降级到 EF5(与脚手架更兼容),并且在问题开始时。

My guess is that the Model (<Binary data>)column is not backward compatible - hence the The provider did not return a ProviderManifest instanceerror since it was unable to decode it.

我的猜测是该Model (<Binary data>)列不向后兼容 - 因此The provider did not return a ProviderManifest instance错误,因为它无法解码它。

I didn't have anything to lose and just wiped out this table completely and ran Update-Database -Verboseand then was back up and running.

我没有什么可失去的,只是把这张桌子完全擦掉了Update-Database -Verbose然后跑了然后又恢复了运行。

If you're in an advanced environment or already in production then wiping out this table may not be the solution, but this way allowed me to get right back to work.

如果您处于高级环境中或已经在生产中,那么清除此表可能不是解决方案,但这种方式使我可以立即恢复工作。

回答by Feras

This error is only present while the .edmx file is open and disappears as soon as the file is closed again.

此错误仅在 .edmx 文件打开时出现,并在文件再次关闭时消失。

This quote from CodePlex, this worked with me (visual studio 2013 /MVC 5)

来自CodePlex 的这句话 ,这对我有用(visual studio 2013 /MVC 5)

回答by GaTechThomas

In using Visual Studio 11 Beta with EF4.1 and ASP.NET MVC, I nearly pulled my hair out until I found

在使用带有 EF4.1 和 ASP.NET MVC 的 Visual Studio 11 Beta 时,我几乎把我的头发拉了出来,直到我发现

http://connect.microsoft.com/VisualStudio/feedback/details/740623/asp-net-mvc-4-default-connection-string-improperly-escaped

http://connect.microsoft.com/VisualStudio/feedback/details/740623/asp-net-mvc-4-default-connection-string-improperly-escaped

To fix my problem, I went into Application_Start and changed

为了解决我的问题,我进入了 Application_Start 并更改了

Database.DefaultConnectionFactory = new SqlConnectionFactory("Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");

Database.DefaultConnectionFactory = new SqlConnectionFactory("Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");

to

Database.DefaultConnectionFactory = new SqlConnectionFactory(@"Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");

Database.DefaultConnectionFactory = new SqlConnectionFactory( @"Data Source=(localdb)\v11.0; Integrated Security=True; MultipleActiveResultSets=True");