【发布时间】:2018-02-18 16:42:46
【问题描述】:
我正在运行 Windows 10、VS 2017 和 SQL Server 2017(版本 14.0.1000.169,开发人员版(64 位))的 x64 开发盒上开发 C# 应用程序。我正在使用 AdventureWorks2016 数据库测试我的应用程序。读取[HumanResources].[Employee] 记录会为数据类型为hierarchyId 的OrganizationNode 字段抛出有据可查的"DataReader.GetFieldType returned null" 异常。
我已经尝试了 SO 问题 DataReader.GetFieldType returned null 中描述的前 2 个答案中的修复,但它们对我不起作用:
-
我尝试了我机器上可用的 dll 副本(即,向 dll 添加了一个引用并使其成为
local copy = true):C:\Program Files (x86)\Microsoft SQL Server\120\SDK\AssembliesC:\Program Files (x86)\Microsoft SQL Server\140\DAC\binC:\Program Files (x86)\Microsoft SQL Server\140\SDK\AssembliesC:\Program Files\Microsoft SQL Server下没有Microsoft.SqlServer.Types.dll的副本(因此,我假设我的机器上没有 64 位版本的 dll)。
用
"Type System Version=SQL Server 2012"修改连接字符串也不起作用
我知道我的 sql 连接和 "Fill" 命令可以正常工作,因为当我从没有 hierarchyId、geography 或 geometry 字段的 AdventureWorks2016 表中读取记录时,它可以正常工作。
sqlConnection.Open();
sqlCommand.CommandType = CommandType.Text;
sqlCommand.Connection = sqlConnection;
sqlCommand.CommandText = primaryKeyQueryString;
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
sqlDataAdapter.Fill(dt);
sqlDataAdapter.Dispose();
sqlConnection.Close();
您知道哪个版本的Microsoft.SqlServer.Types.dll 可以解决我的 SQL Server 2017 问题吗?
如果是这样,我在哪里可以得到它的副本?
我是否需要安装较旧的 SQL Server dll 并将其与我的应用程序一起分发?
【问题讨论】:
标签: c# sql-server exception