在我的业务逻辑中,我多次使用多个 oracle 查询。打开和关闭 oracle 连接的最佳方法是什么?
private void update()
{
OracleConnection con = new OracleConnection("Connection Statement");
OracleCommand command = new OracleCommand("Select Statement");
con.Open();
OracleDataReader reader = command.ExecuteReader();
reader.Close();
con.Close();
// A for loop
con.Open();
command = new OracleCommand("Update statement");
command.ExecuteNonQuery();
con.Close();
con.Open();
command = new OracleCommand("Second Update statement");
command.ExecuteNonQuery();
con.Close();
}
我的代码看起来像这样。我应该为每个命令打开和关闭我的 oracle 连接,还是在第一个命令之前打开并在最后一个命令之后关闭。
PS 这个更新函数在我的应用程序中被调用了 100 多次。