Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Using Windows forms and vb.net

I am experiencing the DataReader.GetFieldType(55) returned null error which is related to missing sql server types.

I cannot reproduce the error from my computer, it only occurs when deployed.

What I have tried:

I have added the sql server types dll to my project as well as the SqlServerTypes folder with x64, x86 and Loader.cs inside.

I have converted the Loader.cs to vb using a link to an answer below.

I've also added this to my app.config:
HTML
<dependentAssembly>
    <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="00000" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
  </dependentAssembly>
Posted
Updated 3-Feb-21 23:27pm
v5
Comments
[no name] 24-Sep-19 13:48pm    
Get a copy of a database / table that has the issue and test with that. Maybe your database is out of sync / out of date.

If it's returning null, there are two possibilities. First, there is no 55th column in the result set the DataReader is going through.

And 2nd, the returned column does exist, but is defined as a UserDefinedType on the database side. You cannot get the type on the client side for one of these. Your query is going to have to break the user type into a bunch of base fields that hold the appropriate data.
 
Share this answer
 
Comments
Member 14476420 24-Sep-19 12:59pm    
running this query on the database: select * from sys.types order by system_type_id asc
I can see that there is no sql server data type 55, so maybe the 2nd part of your answer is the way to go
Dave Kreskowiak 24-Sep-19 15:06pm    
There is no such thing as Type 55 in SQL server. You seem to not understand what GetFieldType does. It returns the .NET Framework equivalent type of the database type for the column number in the result set of your SELECT query in your DataReader.

We can't tell you what's wrong because se can't see the failing code and we know nothing about your database design and what your query is supposed to be returning.

Oh, and if you're using SELECT * in your query, you're making a huge mistake.


It does NOT go to the database and attempt to lookup type information for some arbitrary "Type #55".

What you told the code to do was get the .NET type for the 55th column of the result set your SqlDataReader is returning from the database.
 
Share this answer
 
Comments
Member 14476420 24-Sep-19 12:52pm    
Thanks but as I have explained in my question, I've already tried that

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900