尝试使用指向一个ODBC DSN连接字符串关键字时不支持异常 [英] Keyword not supported exception when attempting to use a connection string that points to a ODBC DSN

查看:778
本文介绍了尝试使用指向一个ODBC DSN连接字符串关键字时不支持异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个ODBC DSN为我的Asp.Net MVC应用程序的数据库访问。其中一个主要的原因是它可以很容易地保持数据库的凭据(如服务器地址,端口,用户名和密码)进行源头控制,而不妨碍我发布的能力。

I created an ODBC DSN for my Asp.Net MVC application's database access. One of the main reasons is it makes it easy to keep database credentials (such as server address, port, username, and password) out of source control without hindering my publishing abilities.

所以我改变了我的连接是 DSN = MyDSN

So I changed my connection to be DSN=MyDSN.

不幸的是,当我跑我的实体框架查询,我得到异常详细信息:System.ArgumentException:关键字不支持:DSN

Unfortunately, when I run my Entity Framework queries I get Exception Details: System.ArgumentException: Keyword not supported: 'dsn'.

有谁知道我在做什么错了?

Does anyone know what I am doing wrong?

推荐答案

如果你想使用ODBC DSN连接字符串必须使用 System.Data.Odbc 本地提供商,而不是托管SQL客户端。

If you want to use ODBC DSN your connection string must use System.Data.Odbc native provider instead of managed SQL client.

编辑:

所以,现在从理论到实践。由于内部EF实现它不工作。 EF内部调用了一些方法,试图让 DbProviderFactory 从创建的连接。问题是,这个属性是在的DbConnection 定义,它返回。只有的SqlConnection 覆盖性和返回正确的工厂。所以EF不使用默认的ODBC提供工作和这里很清楚地描述这是为什么。

So now from theory to practice. It doesn't work because of internal EF implementation. EF internally calls some method which tries to get DbProviderFactory from the created connection. The problem is that this property is defined in DbConnection and it returns null. Only SqlConnection overrides property and returns correct factory. So EF doesn't work with default ODBC provider and here is very clearly described why.

这篇关于尝试使用指向一个ODBC DSN连接字符串关键字时不支持异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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