尝试使用指向一个ODBC DSN连接字符串关键字时不支持异常

编程入门 行业动态 更新时间:2024-10-15 14:18:27
本文介绍了尝试使用指向一个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连接字符串关键字时不支持异常

本文发布于:2023-11-03 18:55:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555818.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不支持   字符串   异常   关键字   ODBC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!