zoukankan      html  css  js  c++  java
  • SQL SERVER(geography/geometry/hierarchyid):DataReader.GetFieldType(10) returned null

      geometry、geography、hierarchyid 等类型的字段,不能使用 DataAdapter 往 DataSet 填充。

            使用 SQL Profiler 攔截程式對資料庫送出的 SQL 命令,發現該 SQL 所查詢的資料表的第五個欄位的型別是 geometry。進一步追查,原來 .NET 應用程式若有用到 SQL Server 資料庫的 geometry 型別,該應用程式所在的電腦上就必須額外安裝 SQL Server 2008 R2 Feature Pack。

    参考:https://www.e-learn.cn/content/wangluowenzhang/1355396

    In my db table Layout, there's one column whose type is hierarchyid (column index=4). When trying to set-up new environment (a virtual web-server, created from XEN server), then running the site, I've met with this issue:

    Exception message: DataReader.GetFieldType(4) returned null. Exception data: System.Collections.ListDictionaryInternal

    I've made some search and found out there are already some topic on it (such as on MSDN).

    But even when I added the C:Program FilesMicrosoft SQL Server100SDKAssembliesMicrosoft.SqlServer.Types.dll library, it seems like db type in structure SqlHierarchyId doesn't get recognized.

    "Exception at DataReader.GetFieldType(4) returned null" is still thrown out.

    Note: The issue will be solved if I made installation of C# package in VS2010 onto the environment (Windows Server 2008 RC2), but my boss didn't accept that, because this is purely a simple web-server.

    回答1:

    Reference the Microsoft.SQLServer.Types dll from the project and for the reference set it as "Copy Local" in the properties of the reference. This will package that DLL up with the website when you deploy it. Then you don't need all of SQL Server installed on your web box in order to use the SQL Server data types. I did this for my website because it was using the geography data type columns and I was getting the same error.



    回答2:

    The solution that works for me is add "Type System Version=SQL Server 2012" to connection string.

    Example: string connectionString = "Data Source=myserver;Initial Catalog=mydatabase;User ID=sa;Password=*******;Type System Version=SQL Server 2012;";



    回答3:

    I tried to resolve this issue by adding the Microsoft.SqlServer.Types NuGet package to my project, but that alone did not help. I also had to add the following to the <assemblyBinding> element of my project's App.config:

    <runtime>   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">   .   .   .     <dependentAssembly>       <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />       <bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />     </dependentAssembly>   .   .   .   </assemblyBinding> </runtime> 



    回答4:

    Rather than changing your project and adding a reference to Microsoft.SQLServer.Types dll you could just put it into the GAC.

    In my case I had three versions on my dev machine and added them to the server GAC:

     gacutil.exe -i .10.0.0.0__89845dcd8080cc91Microsoft.SqlServer.Types.dll  gacutil.exe -i .11.0.0.0__89845dcd8080cc91Microsoft.SqlServer.Types.dll  gacutil.exe -i .12.0.0.0__89845dcd8080cc91Microsoft.SqlServer.Types.dll 

    I had other SQL related third party .NET tools on the server that had the same error. After adding the assemblies to the GAC, they all worked fine.

    While I don't put my own assemblies into the GAC, I think it is okay to put some Microsoft SQL-Server assemblies there because they affect multiple applications.



    回答5:

    After other solution if you still have error try to delete in web.config

    <add assembly="Microsoft.SqlServer.Types, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/> 

    copy file Microsoft.SqlServer.Types.dll to bin folder (or/and add reference)

    or/and add "Type System Version=SQL Server 2012;" in sqlconnectionstring



    回答6:

    For those experiencing this problem with PowerShell, I was able to fix my problem by installing the SQLSysClrTypes.msi package from Microsoft for SQL Server 2016 and restarting powershell. The download page is confusing to navigate, click "Download" and search the page for SQLSysClrTypes. Select the right architecture.

    Exception calling "Fill" with "1" argument(s): "DataReader.GetFieldType(24)  returned null." At MyScript.ps1:15 char:5 +     $adapter.Fill($ds) | Out-Null +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     + CategoryInfo          : NotSpecified: (:) [],  ParentContainsErrorRecordException     + FullyQualifiedErrorId : InvalidOperationException 

    In my case, the offending data type was Microsoft.SqlServer.Types.SqlGeography in position (24) This field worked fine inside AppVeyor with SQL Server 2016 installed, but wouldn't run on my local environment.

    I found several articles explaining why this occurs and some specified to use NuGet to fetch the latest Microsoft.SqlServer.Types.dll, but in my case, this didn't help, nor did any attempt to replace the assemblyGAC_... version with one from Install-Package and friends.

    Note: Installing the .msi wasn't as straight forward as one would expect because through trial and error, I had installed several older "Microsoft SQL Server System CLR Types". This resulted in the MSI only offering "Repair" and "Remove". If this occurs, chose "Remove" and the run the installer again.

    Installing the correct version and restarting PowerShell did the trick.

  • 相关阅读:
    使用私有api实现自己的iphone桌面,并根据app的使用次数对app排序
    坐标系的属性
    带坐标轴的几何画板
    空间几何体的直观图matlab
    设置npm的registry
    (原创)机器学习之numpy库中常用的函数介绍(一)
    (原创)交叉编译 tesseract
    (原创)计算机视觉之数学原理-基础篇
    (原创)nRF51 DFU 初始化包介绍及生成工具
    (原创)使用nRF51822/nRF51422创建一个简单的BLE应用 ---入门实例手册(中文)之五
  • 原文地址:https://www.cnblogs.com/wanggang2016/p/12444298.html
Copyright © 2011-2022 走看看