Oracle连接超时

时间:2016-11-23 05:26:43

标签: c# oracle odp.net

我有一个应用程序,它在一天中的特定时间查询数据库,然后在接下来的3-4个小时内空闲,然后再次向数据库查询一些数据,但它只执行一次,在第二次尝试时它正在抛出错误。

using (OracleConnection connection = new OracleConnection())
{
    connection.ConnectionString = connectionString;
    connection.Open();
    OracleCommand command = connection.CreateCommand();
    string sql = _query;
    command.CommandText = sql;

    OracleDataAdapter oAdapter = new OracleDataAdapter(sql, connection);
    oAdapter.Fill(myDataSet);
    connection.Close();
    return myDataSet;
}

错误被抛出:

oAdapter.Fill(myDataSet);

错误统计信息为ORA-03113: end-of-file on communication channel

据我所知,连接应在一次调用后处理,并且应在每个请求上创建另一个连接。我已检查过与服务器的连接是否可用并正在侦听,在发生此错误时没有网络问题。

1 个答案:

答案 0 :(得分:1)

我明白了,因为任何寻找答案的人都是我在使用语句中调用return myDataSet;首先我没有注意到它,但是OracleConnection是从IDisposable继承而且我是使用语句返回数据集,因此它永远不会被正确处理掉。所以我刚从

改变了这个
using (OracleConnection connection = new OracleConnection())
{
connection.ConnectionString = connectionString;
connection.Open();
OracleCommand command = connection.CreateCommand();
string sql = _query;
command.CommandText = sql;
OracleDataAdapter oAdapter = new OracleDataAdapter(sql, connection);
oAdapter.Fill(myDataSet);
connection.Close();
return myDataSet;}

using (OracleConnection connection = new OracleConnection()){
connection.ConnectionString = connectionString;
connection.Open();
OracleCommand command = connection.CreateCommand();
string sql = _query;
command.CommandText = sql;
OracleDataAdapter oAdapter = new OracleDataAdapter(sql, connection);
oAdapter.Fill(myDataSet);
connection.Close(); }
return myDataSet;