【发布时间】:2018-11-02 21:26:50
【问题描述】:
我正在尝试在应用程序中使用 Oracle 的托管数据访问客户端(版本 4.121.1.0)。我对数据库进行小查询没有问题,但是我遇到了返回大结果的查询的问题。
我从包含大约 137,000 条记录的表中选择两列(所有行)。一列是一个数字(id),另一列是一大堆文本。我正在使用数据阅读器将所有带有 id 的 clob 数据读取到对象列表中。所有这一切都很好,大约需要 10 分钟才能完成所有这些(球块可能很大)。
填充数组后,我在连接上调用 Close() 方法并等待,等待,再等待...关闭连接大约需要 1 小时 25 分钟。一旦连接关闭,应用程序将继续正常运行。为什么关闭连接需要这么长时间?
这是我当前的代码示例,它显示了问题。
List<StudentData> studentData = new List<StudentData>();
using (OracleConnection connection = new OracleConnection(this.ConnectionString))
{
try
{
// Get all the clobs
OracleCommand cmdGetClobs = new OracleCommand("SELECT STUDENT_NUMBER, CUSTOM FROM PS.STUDENTS", connection);
connection.Open();
var rdr = cmdGetClobs.ExecuteReader();
while (rdr.Read())
{
System.Char[] clobData = new System.Char[rdr.GetOracleClob(1).Length];
rdr.GetChars(1, 0, clobData, 0, (int)rdr.GetOracleClob(1).Length);
string studentNumber = rdr["STUDENT_NUMBER"].ToString().Trim();
StudentData data = new StudentData()
{
Student_Number = studentNumber,
ClobValue = clobData
};
studentData.Add(data);
}
// I've tried with, and without calling the dispose methods.
rdr.Dispose();
cmdGetClobs.Dispose();
connection.Close(); // <--- App will hang here for about 1.5 hours
connection.Dispose();
}
finally
{
if (connection.State != System.Data.ConnectionState.Closed)
{
connection.Close();
}
}
}
【问题讨论】:
-
叹息...没有人吗?更新...我更新了一个现有的工作应用程序,该应用程序使用旧的、非托管的 odp.net 进行相同的查询。我在使用托管代码时遇到了同样的问题,但使用非托管代码可以正常工作。