oracle ExecuteScalar in parallel programming sometimes returns null

[亡魂溺海] 提交于 2019-12-13 04:23:13

问题


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();
    }
}

回答1:


As I known that if you close a connection in JDBC, its depending res would be closed as well.



来源:https://stackoverflow.com/questions/24296265/oracle-executescalar-in-parallel-programming-sometimes-returns-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!