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

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

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

发布评论

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

>www.elefans.com

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