所以我更改了我的连接是 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的连接字符串时,不支持关键字异常
发布评论