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 Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.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.
8条答案
按热度按时间ewm0tg9j1#
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.axkjgtzd2#
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:bbmckpt73#
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;";
kninwzqo4#
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:
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.
hjzp0vay5#
After other solution if you still have error try to delete in web.config
copy file Microsoft.SqlServer.Types.dll to bin folder (or/and add reference)
or/and add "Type System Version=SQL Server 2012;" in sqlconnectionstring
nhaq1z216#
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 forSQLSysClrTypes
. Select the right architecture.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 latestMicrosoft.SqlServer.Types.dll
, but in my case, this didn't help, nor did any attempt to replace theassembly\GAC_...
version with one fromInstall-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.
qyswt5oh7#
For me had to add 10.0.0.0__89845dcd8080cc91 folder inside it added the
Microsoft.SqlServer.Types.dll
for version 10
to C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Types
Probably there's hidden dependency that uses GAC instead of the the project directory
qq24tv8q8#
Using (the oldest) version 10.50.1600.1 fixed this for me.