Thursday, March 22, 2012

Data Type Exception Error

Error:
This is only part of the errors, since it is quite long, I will just quote the core part.

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: DataReader.GetFieldType(5) returned null.

This happens when I deploy a web application developed under Visual Studio .Net 2010 using SQL Server 2008 R2 for the database. The query used happen to retrieve fields of type hierarcyid. It works on other machines, this is the first time I encountered such error.
After searching through the internet, I found a solution in a thread on MSDN forum.

Seems that not only for table with field of CLR data type: hierarchyid, fields of Spatial type: geometry and geography also could result in such error.

Solution:
Add the file C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.SqlServer.Types.dll to the project (as a reference), or simply copy the DLL file to the bin folder in which the project is deployed.

Reason:
According to the post, it seems that the new SQL Server 2008 data types are not native .NET data types. On the machine where the application is deployed to, the DLL file was not available, so the DataAdapter can't initialize the data types correctly.
Share:

You may be intersted in

Related Posts

Updating Table Containing Xml Column via LinkedServer

If you are trying to update a table containing XML column via Linked Server in SQL Server, and you are not able to, you are not alone. There...

About Me

My photo
Is an ordinary man, with a little knowledge to share and high dreams to achieve. I'd be glad if I can help others, 'coz the only thing for the triumph of evil is for a good man to do nothing.

About Blog

You can find a lot of debugging and deploying problems while developing applications in .NET and Visual Basic here. There are also some querying tips in SQL and typical source codes which might be useful shared here.

Popular Posts

Blogroll

Followers

Leave a Message