Marisk
2/21/2002 9:24:00 PM
A puzzler :
I'm getting an invalid cast exception when accessing records using
SqlDataReader call to an ST proc as in the following code :
SqlDatareader result = command.ExecuteReader ();
while (result.Read ())
{
string s = (string) result ["somefield'];
...
}
The "somefield" is an nvarchar in the db and can be NULL.
The odd thing is that the same code runs against the same db image on a
different server and does not throw the exception. Both environments are
virtually identical, the only difference being that the data tables on the
offending machine were generated via Excel files that were exported from the
"good" machine.
I've experimented with ANSI_NULL and QUOTED_IDENTIFIER settings to no
effect.
I can fix the problem by using the Convert.IsDBNull function, but I am
mystified as to the cause of this anomaly.
Any suggestions ??