When will SQLServer 2005 fail to insert / update AND ALSO NOT "throw" the exception?

After running a query to insert or update a SQLServer 2005 database, in what scenario (if at all possible) this can happen - SQLServer 2005 does not execute or does the insert / update, AND ALSO DOES NOT "CRUSH" THE EXCEPTION?

Note that we are running an insert or update query through a SqlCommand object. Also note that the table that uses an insert or update query has

  • identification fields
  • fields that are not null,
  • with appropriate data types
  • fields that are help keys
  • fields where control constraints apply
  • and etc.

Suppose that the WHERE clause in the update query finds the fix that needs to be updated.

Is it safe to assume that after we execute SqlCommand.ExecuteNonQuery (), if no insert or update occurs, then the un-handled exception will be ALLWAYS? Otherwise, we can assume that the insert or update request was successful.

0


source to share


3 answers


You can assume that an exception (SqlException) will be thrown IF the INSERT / UPDATE includes a WHERE clause that does not match any rows.



0


source


Look at the return value of ExecuteNonQuery () to see the number of records affected.



0


source


Move your logic into your database stored procedures and throw exceptions (RAISERROR) from there. Then the command (which will call the corresponding stored procedure) will have the required exceptions.

0


source







All Articles