I used parallel programming to perform two parallel oracle database queries. Sometimes the "res" object returns as null. Any idea why? Note that this is a count query of the same table and nothing is modifying this table so the database table and the query are not changing.
string query = "select count(*) from SALES_ADVENTUREWORKS2012.SALESORDERDETAIL where PRODUCTID=709";
tasks[0] = Task.Factory.StartNew(() => db.ExecScalarQuery(query));
tasks[1] = Task.Factory.StartNew(() => db.ExecScalarQuery(query));
Task.WaitAll(tasks);
//---------------
public void ExecScalarQuery(String query)
{
OracleConnection conn = new OracleConnection(connectionString);
try
{
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = query;// "select count(*) from SALES_ADVENTUREWORKS2012.SALESORDERDETAIL where PRODUCTID=709";
cmd.CommandType = CommandType.Text;
cmd.CommandTimeout = QUERY_TIMEOUT;
Object res cmd.ExecuteScalar();
}
finally
{
conn.Close();
}
}
As I known that if you close a connection in JDBC, its depending res would be closed as well.