Linq to SQL Error: Specified cast is not valid

August 13, 2008

I’ve been working with LINQ to SQL a fair bit recently, which so far has proved to be a very efficient and clean way to access data, although I think I found a bug! One of my SQL (2005) tables was defined as TinyInt, which the .Net framework saw as a boolean value, giving me a runtime error of ‘Specified cast is not valid’. I applied a work-around of changing the SQL data type to int, ans all was fine, although I’m not 100% happy with that as a fix.

I’ve also read of this error occuring after changing the datatype on a column, where the LINQ to SQL DBML hasnt caught up with the change, in this case the best option is to delete the table from the LINQ to SQL designer surface, then re-add, unless of course you have made any specific changes on the designer.

Advertisements

2 Responses to “Linq to SQL Error: Specified cast is not valid”

  1. quirksmod3 said

    smallint?

  2. DotNetSi said

    Nope, it was TinyInt

    ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: