For example I have the following tables resulting from:
CREATE TABLE A (Id int, BId int, Number int)
CREATE TABLE B (Id int, Number decimal(10,2))
GO
INSERT INTO A VALUES(1, 3, 10)
INSERT INTO B VALUES(3, 50)
INSERT INTO A VALUES(2, 5, 20)
INSERT INTO B VALUES(5, 671.35)
GO
And I run the following query multiple times:
SELECT * FROM A INNER JOIN B ON A.BId = B.Id
I should get something like:
ID BId Number ID Number
1 3 10 3 50.00
2 5 20 5 671.35
But is it possible for A.Number and column B.Number be in different position (also ID in that respect) so I'll get something like:
ID Number ID BId Number
3 50.00 1 3 10
5 671.35 2 5 20
We are currently experiencing some weird problem that might be resulting from something like this. We have an ASP.NET application, executing a custom reflection based code generated data mapper that is connecting to SQL Server 2008 cluster.
We found sometimes that we get an error like so:
Object of type 'System.Decimal' cannot be converted to type 'System.Int32'
Trying to figure out if this is a behaviour in SQL Server or it's something in the reflection based data mapper engine.
As you can see the field names are the same in the two tables. Thinking perhaps when we tried to do DataReader.GetValue(DataReader.GetOrdinal("Number")), it will return B.Number which is a decimal instead of A.Number which is an int.
To complicate the matter further, this only happen intermittently (but consistently after it happened once on a particular IIS web server in a web farm only).
Say Web Server A is doing okay up until 2:00pm and suddenly, we got this error and we'll keep getting that error on Web Server A until we reset IIS on that server and then it will be okay again.
Something to do w/ connection pooling and how SQL query plan cache perhaps?