Please Help: DB2 C# Weird Error "ExecuteReader requires an open and available Connection"

A

Antoni Mass? Mola

Hi,

I'm building an Intranet for my client.

The computer is running Windows 2000 Server ASP.NET
Version:1.1.4322.573 and DB2 UDB 8.1

DB2 has 10 databases each one with 10-12 tables.

In one ASPX page I need to access the 10 tables for each DB.

When I used to have 4 DB it worked fine, but one there are 5 it
crashes with this error:

"ExecuteReader requires an open and available Connection. The
connection's current state is Closed.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: ExecuteReader
requires an open and available Connection. The connection's current
state is Closed."

Here is the code I use to open the connection and retrieve the
information:

In a file named module.cs I have this

// Module 1
namespace Combalia.Conexiones.ADONET
{
using System;
using System.Data.OleDb;
using System.Data;
using System.IO;
using System.Web;

public class adoConn
{
OleDbConnection mySqlConnection;

public static void Main()
{
adoConn myadoConn = new adoConn();
myadoConn.Run("null");
}

public OleDbDataReader dbSQLSelect(string mySelectQuery)
{
OleDbCommand myCommand = new
OleDbCommand(mySelectQuery,mySqlConnection);
OleDbDataReader myReader = myCommand.ExecuteReader();

return myReader;
}

public bool dbSQLDIU(string myDIUQuery)
{
OleDbCommand myCommand = new
OleDbCommand(myDIUQuery,mySqlConnection);

if(myCommand.ExecuteNonQuery() > 0)
{
return true;
}
else
{
return false;
}
}

public void Run(string sDB)
{
mySqlConnection = new OleDbConnection("Provider=IBMDADB2.1;Data
Source='" + sDB + "';User ID=administrator;Password=xxxxxxx;Network
Address=xxx.xxx.xxx.xxx; Max Pool Size=100;Connection Lifetime=0");

try
{
mySqlConnection.Open();

if(mySqlConnection.State != ConnectionState.Open)
{
mySqlConnection.Open();
}

}
catch
{
Console.WriteLine("No se pudo conectar con {0}",
mySqlConnection.ConnectionString);
}
}

public string Close()
{
mySqlConnection.Close();
OleDbConnection.ReleaseObjectPool();
mySqlConnection.Dispose();
return "ok";
}

}

}

// End Module 1

Then I use this code in the ASPX page:

if(ShowDb1)
{
adoConn adoConn = new adoConn();
adoConn.Run("DBNAME");

OleDbDataReader myReader = adoConn.dbSQLSelect("Select Query");

try {
while (myReader.Read())
{
iTotal += myReader.GetInt32(0);
}

}
finally
{
myReader.Close();
adoConn.Close();
}

myReader = adoConn.dbSQLSelect("Select Query 2");

try {
while (myReader.Read())
{
iSuplidos += myReader.GetInt32(0);
}

}
finally
{
myReader.Close();
}
}
....And so on for each table and DB

Any ideas what might be the problem?

Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top