如果我嘗試調用一個存儲過程並且存在數據庫錯誤,那麼會在我的C#代碼中引發異常嗎?或者我需要檢查存儲過程的結果並自己提出異常?使用Ado.Net存儲過程時可靠地拋出異常嗎?
如:
using (SqlCommand cmd = new SqlCommand("prc_InsertSomething", conn))
{
if (cmd.ExecuteNonQuery() != 1) // should I be doing this bit or not?
{
throw new DataException("Could not insert something");
}
}
感謝
我相信OP是詢問攔截調用應用程序中的異常,而不是存儲過程本身。 – Oded 2010-07-27 09:27:24