我有一个应用程序,它在一天中的特定时间查询数据库,然后在接下来的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
据我所知,连接应在一次调用后处理,并且应在每个请求上创建另一个连接。我已检查过与服务器的连接是否可用并正在侦听,在发生此错误时没有网络问题。
答案 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;