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

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

问题描述

我为我的Asp.Net MVC应用程序的数据库访问创建了一个ODBC DSN。主要原因之一是使数据库凭据(例如服务器地址,端口,用户名和密码)从源代码控制中轻松,而不会妨碍我的发布功能。



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



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



有谁知道我做错了?

解决方案

如果要使用ODBC DSN,连接字符串必须使用 System.Data .Odbc 本机提供程序,而不是托管SQL客户端。



编辑:



现在从理论到实践。由于内部的EF实施,它不起作用。 EF内部调用一些尝试从创建的连接获取 DbProviderFactory 的方法。问题是该属性在 DbConnection 中定义,并返回 null 。只有 SqlConnection 覆盖属性并返回正确的工厂。所以EF不适用于默认的ODBC提供程序,并且这里非常清楚地描述为什么。


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.

So I changed my connection to be DSN=MyDSN.

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?

解决方案

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

Edit:

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天全站免登陆