I'm using OracleCommand.ExecuteNonQuery() to insert into a table. Everything works fine but occasionally records are not inserted. So is it possible that ExecuteNonQuery() doesn't insert the record and also doesn't throw an exception?
I'm not using stored procedures. I'm not using a transaction. I am logging any exception that is thrown by ExecuteNonQuery() but apparently no exception is thrown... I am also not checking the return value of ExecuteNonQuery(). But is it possible that ExecuteNonQuery returns another value than 1 if the insert is successful?
It shouldn't. ExecuteNonQuery returns an integer indicating the number of rows affected. If no rows were inserted, 0 should be returned. It should thrown an exception when it fails to execute the query. E.x.: the connection is closed, the table doesn't exist, etc.
Not unless you're swallowing the exception somewhere, like this:
try
{
DoSomethingOnTheDbThatMightThrowAnException();
}
catch(Exception ex)
{
// Do nothing, thus swallowing the exception
}
Also, check the return value of ExecuteNonQuery(). If it is 0, you might want to consider throwing an exception yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With