I’m getting an exception from SQL Data Reader (MS SQL as datastore) and I’d like to know which column name causes this Exception to be thrown. But I cannot find it in the InnerException.. nowhere.
((System.InvalidOperationException)ex.InnerException).StackTrace:
System.Data.SqlClient.SqlDataReader.ReadColumnHeader(Int32 i)
System.Data.SqlClient.SqlDataReader.IsDBNull(Int32 i)
...
Where is it hidden please ?
You can’t. The data reader does not communicate that in its stack trace. What you can do is wrapping the use of the data reader in another class. In a project I’m working on we used extension methods for this. The class looks like this:
You can use it as follows:
btw. Such an class also allows you to get
Nullable<T>objects back and get rid of those manualDbNullconversions you else need to do.