OracleDataAdapter在Windows XP中的Fill方法上挂起。 调试在Windows 7中工作正常,但VS2008挂起在Windows XP上。 这同样适用于应用程序的发布版本。使用的sql查询无关,我使用简单查询测试了函数,它们都失败了。
以下是说明初始代码的代码段:
public static string DBSelectString(string ssql)
{
try
{
OracleDataAdapter da = new OracleDataAdapter();
DataTable dt = new DataTable();
da.SelectCommand = new OracleCommand(ssql, Connection);
da.Fill(dt);
return dt.Rows[0].ItemArray[0].ToString();
}
catch (Exception ex)
{
Utils.Log(ex.Message);
return string.Empty;
}
}
使用OracleDataReader仍然会挂起,但我设法找到了解决方法。
public static string DBSelectStringDR(string ssql)
{
OracleDataReader reader = null;
try
{
Connection.Open();
OracleCommand command = new OracleCommand(ssql, Connection);
reader = command.ExecuteReader();
if (reader.HasRows)
{
//reader.Read();
//return reader.GetValue(0).ToString(); <-------- normally hangs here
try
{
//workaround:
//force exception, since Read has not been executed
string test = reader.GetValue(0).ToString();
}
catch { }
// then, everything works fine
reader.Read();
return reader.GetValue(0).ToString();
}
else
{
return string.Empty;
}
}
catch (Exception ex)
{
Utils.Log(ex.Message);
return string.Empty;
}
finally
{
if (reader != null) reader.Close();
Connection.Close();
}
}
有什么想法吗?