我時許調用下面打開在OracleDataReader循環另一個連接如oracle的會話不會關閉
private ArrayList GetORA()
{
ArrayList arr = new ArrayList();
string connectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=xx)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));User ID=kcdev2usr;Password=password;ENLIST=FALSE;Pooling=true;Max Pool Size=20;";
const string queryString = "select * from MASTER_TABLE";
using (OracleConnection connection = new OracleConnection(connectionString))
{
OracleCommand command = new OracleCommand(queryString, connection);
connection.Open();
OracleDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
try
{
while (reader.Read())
{
Master m = new Master();
m.ID = reader["ID"].ToString();
m.obj = GetAnother(reader["SOME"].ToString());
arr.Add(m);
}
}
finally
{
reader.Close();
}
}
return arr;
}
private Object GetAnother(string some)
{
// Do something
string getNextID = PutSome(some);
//=====
Object obj = null;
string connectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=xx)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));User ID=kcdev2usr;Password=password;ENLIST=FALSE;Pooling=true;Max Pool Size=20;";
const string queryString = "SELECT PAGE_NAME FROM ANOTHER_TABLE WHERE ID=:ID";
using (OracleConnection connection = new OracleConnection(connectionString))
{
OracleCommand command = new OracleCommand(queryString, connection);
command.Parameters.Add("ID",getNextID);
connection.Open();
OracleDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
try
{
while (reader.Read())
{
obj = CreateObj(dr["PAGE_NAME"].ToString());
}
}
finally
{
reader.Close();
}
}
return obj;
}
下OracleDataReader循環代碼另一個連接然後不關閉有關會話問題..我我試圖移動問題的方法循環這樣的
private ArrayList GetORA()
{
ArrayList arr = new ArrayList();
string connectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=xx)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));User ID=kcdev2usr;Password=password;ENLIST=FALSE;Pooling=true;Max Pool Size=20;";
const string queryString = "select * from MASTER_TABLE";
using (OracleConnection connection = new OracleConnection(connectionString))
{
OracleCommand command = new OracleCommand(queryString, connection);
connection.Open();
OracleDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
try
{
while (reader.Read())
{
Master m = new Master();
m.ID = reader["ID"].ToString();
m.Some = reader["SOME"].ToString();
arr.Add(m);
}
}
finally
{
reader.Close();
}
foreach (var item in arr)
{
item.obj = GetAnother(item.Some);
}
}
return arr;
}
所有甲骨文會議是乾淨,清楚,爲什麼?
- 我的東西我的代碼不好,但我想知道ODP.Net管理oracle會話有什麼區別。
ps。我用「Oracle.DataAccess.dll」版本4.121.2.0
不需要顯式調用Dispose(),因爲using語句處理該問題 –
是的,我想重用會話,但是我幾天無法優化舊代碼(這是舊的應用),所以它需要一些快速解決方案在修改整個源代碼之前更改這個 – Rnan