并行编程中的oracle ExecuteScalar有时返回null [英] oracle ExecuteScalar in parallel programming sometimes returns null
本文介绍了并行编程中的oracle ExecuteScalar有时返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用并行编程来执行两个并行的oracle数据库查询. 有时,"res"对象返回为null. 知道为什么吗?请注意,这是对同一表的计数查询,没有任何修改该表的操作,因此数据库表和查询都不会更改.
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();
}
}
推荐答案
我知道,如果您在JDBC中关闭连接,其依赖的资源也会被关闭.
As I known that if you close a connection in JDBC, its depending res would be closed as well.
这篇关于并行编程中的oracle ExecuteScalar有时返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文