Problem with AleDBConnection to an ACCESS database

L

Lars

Hi

I have the code added below in one of my project. The first time I execute
the code it gives the result I would expect but if I call the same method
again I get an "Unknow Error" when I try to call "reader.Read()".

I have make sure that I close every reader and connection in every method.

Can the problem has to do with the fact that I do more calls in other
methods that also creates a connection to the database. Can you do this with
OleDbConnections. Of course it's not the same objects.

My guess would be that it some how has to do with the connection. The SQL
code works the first time I do the commands to the database. If I run the
same command (click the Search button) emediatly after the first result is
shown I get the error.

Do I have to wait and see if the connection was closed before I make another
call?


Any ideas

Lars

Here's the code
=================

static public int CreateDetailedReport(Table T, String ConnectionString,
String aid, String datum)
{
String SelectPrograms = String.Empty;
String sDate = String.Empty;
String Installs = String.Empty;
String S = String.Empty;
try
{
if (aid == "")
{
SelectPrograms = "select distinct(program) from installs where
datum LIKE @datum";
}
else
{
SelectPrograms = "select distinct(program) from installs where
aid=@aid and datum LIKE @datum";
}
ListItem LI = null;
OleDbDataReader reader = null;
OleDbConnection connection = new OleDbConnection(ConnectionString);
OleDbCommand command = new OleDbCommand(SelectPrograms);
TableRow Row=null;
TableCell Cell=null;
int nRow=0;
ArrayList ListRows = new ArrayList();
ArrayList ListColls = new ArrayList();

int counts = 0;

if (aid != "")
{
command.Parameters.Add(new OleDbParameter("@aid", aid));
}
command.Parameters.Add(new OleDbParameter("@datum", datum));

command.Connection = connection;
connection.Open();
reader = command.ExecuteReader();

T.Rows.Clear();
Row = new TableRow();
Cell = new TableCell();
Cell.Text = "Date";
Row.Cells.Add(Cell);

while (reader.Read())
{
Cell = new TableCell();
Cell.Text = reader.GetString(0).Clone().ToString();
ListColls.Add(Cell.Text);
Row.Cells.Add(Cell);
}
Cell = new TableCell();
Cell.Text = " All Programs ";
Row.Cells.Add(Cell);
T.Rows.Add(Row);

reader.Close();
connection.Close();

AffiliateSelectDates(ListRows, ConnectionString, aid, datum);

foreach( Object R in ListRows )
{
Row = new TableRow();
Cell = new TableCell();
Cell.Text = Convert.ToString(R);
Row.Cells.Add(Cell);

foreach( Object C in ListColls )
{
Cell = new TableCell();
Cell.Text = AffiliatePerDayInstallPerProgram(ConnectionString,
aid, Convert.ToString(C), Convert.ToString(R) + "%");
Row.Cells.Add(Cell);
}

Cell = new TableCell();
Cell.Text = AffiliatePerDayInstallTotal(ConnectionString, aid,
Convert.ToString(R) + "%");
Row.Cells.Add(Cell);
T.Rows.Add(Row);
}

Cell = new TableCell();
Cell.Text = "Sum";
Row = new TableRow();
Row.Cells.Add(Cell);

foreach( Object C in ListColls )
{
Cell = new TableCell();
Cell.Text = AffiliatePerDayInstallPerProgram(ConnectionString,
aid, Convert.ToString(C), datum + "%");
Row.Cells.Add(Cell);
}
Cell = new TableCell();
Cell.Text = AffiliatePerDayInstallTotal(ConnectionString, aid, datum
+ "%");
Row.Cells.Add(Cell);
T.Rows.Add(Row);

return counts;
}
catch (Exception ex)
{
return 0;
}
}


===== End Code =========
 

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