Question : SqlCommand.ExecuteReader not returning any error even when there is an error in the query.

I am querying SQL Server 2005 in .NET/C# using SqlCommand.ExecuteReader to return a SqlDataReader object.

When a query, which should throw an error is passed in, it returns an empty recordset with no indication at all that it failed i.e. there is no error thrown. So in my application code I cannot tell the difference between whether the query should be really be returning 0 rows or whether there was an error in the query as there was in this example.

When the same example query is run in query analyser it gives the error "Msg 245, Level 16, State 1, Line 6 Conversion failed when converting the varchar value 'blah' to data type int.".

Obviously I know how to solve the error in question but what I need is for the error to be returned to the application so that it can handle the error appropriately.

So I really need to know that it failed rather then receiving an empty recordset - is there a way to persuade it to?

Thanks

PS - this is a duplicate post because the original post got lots of off-track responses which I know can put people off looking at it.

Answer : SqlCommand.ExecuteReader not returning any error even when there is an error in the query.

The difference will be in your keyboard layout. You will be using French to type but your kb layout is English so it will take you some time to work out which key you need to press for certain French letters. Apart from that everything will be the same.
Random Solutions  
 
programming4us programming4us