我打電話我applciation OracleCommandd.ExecuteNonquery()
和我得到「連接必須是打開此操作」在下面的代碼異常異常:「連接必須是打開此操作」上ODP
using (OracleConnection connection = new OracleConnection(ConnectionString))
{
OracleCommand oracleCommand = new OracleCommand(procedureName, connection);
oracleCommand.CommandType = CommandType.StoredProcedure;
oracleCommand.ExecuteNonQuery();
}
當我在using
語句後面放置connection.Open();
時,不會發生異常,但不會發生using
語句處理連接的打開和關閉階段(實際上打開close關閉連接池到連接池)。
我喜歡烏爾辦法,但你怎麼能捕捉異常,如果在所有它長大的嗎?同時使用Using語句和try catch塊是否是一個好習慣? – Biki
是的,你可以用一個try-catch塊封裝所有這些。 –