简体   繁体   English

在 EF 6 连接字符串中使用 provider=SQLOLEDB

[英]Use of provider=SQLOLEDB in EF 6 connection string

We have legacy connection strings in use by different sql clients from years past.过去几年,我们有不同的 sql 客户使用的遗留连接字符串。 The connection string has legacy syntax: "Provider=SQLOLEDB" .连接字符串具有旧语法: "Provider=SQLOLEDB"

Provider=SQLOLEDB;Data Source=<servername>;Initial Catalog=<dbname>;Integrated Security=SSPI

EF6 uses different SQL client and providers obviously. EF6 显然使用不同的 SQL 客户端和提供程序。

So my question is, does there exist a way to configure EF6 to use a provider or connection provider factory that will know how to deal with the provider keyword in the connection string?所以我的问题是,是否存在一种方法可以将 EF6 配置为使用知道如何处理连接字符串中的提供程序关键字的提供程序或连接提供程序工厂? Currently I'm getting the error message目前我收到错误消息

Keyword not supported: 'provider'.不支持关键字:'provider'。

I was hoping there might be a way to avoid changing the connection string that doesn't involve a run-time tweak to remove the keyword from the original connection string.我希望可能有一种方法可以避免更改不涉及运行时调整的连接字符串,以从原始连接字符串中删除关键字。

The problem is that Entity Framework is a .NET thing.问题是 Entity Framework 是一个 .NET 的东西。 And in ADO.net you are not allowed to use the SQLOLEDB provider.并且在 ADO.net 中,您不允许使用SQLOLEDB提供程序。

Even though you are actually using the OleDbConnection class , and normally OLEDB lets you specify the OLEDB Provider , you're just not allowed to here.即使您实际上使用的是OleDbConnection class ,并且通常 OLEDB 允许您指定 OLEDB Provider ,但您在这里是不允许的。

The ADO.net OleDbConnection class detects if you try to use the SQLOLEDB provider, and simply throws an error. ADO.net OleDbConnection class 检测您是否尝试使用SQLOLEDB提供程序,并简单地抛出错误。

I know that's not (yet) what you're seeing here.我知道那不是(还)你在这里看到的。 What you're seeing here is explained here :你在这里看到的是在这里解释的:

The approach you are using to build the EF connection string is correct.您用于构建 EF 连接字符串的方法是正确的。

BUT...但...

The Entity Framework only works with Providers (ie SqlClient) that support something called provider services.实体框架只与支持提供者服务的提供者(即 SqlClient)一起工作。

The OleDB provider doesn't support 'Provider Services' so you can't use EF with the OleDb (unless you can find a third party OleDb provider with support for EF). OleDB 提供程序不支持“提供程序服务”,因此您不能将 EF 与 OleDb 一起使用(除非您可以找到支持 EF 的第三方 OleDb 提供程序)。

Hope this helps希望这可以帮助

Alex亚历克斯

(Entity Framework Team, Microsoft) (实体框架团队,微软)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM