Re: Garbage Collection in .NET?
Posted by: Timothy Graupmann
Date: January 27, 2005 05:42PM

I've seen the same problem. It has to be you not closing your connections. It might be throwing an exception, which in that case you still need to close the connection. Here's a sample of what I use.

Taken from:
http://cvs.sourceforge.net/viewcvs.py/tagelflax/tagml/TAGMLWS/DbLayer/connection.cs?view=markup

static public Action[] GetLastActionList(ref UInt32 workspaceId,
ref Int64 lastActionId)
{
ArrayList newActionList = new ArrayList();

IDbConnection myConnection = DBFactory.CreateConnection();
myConnection.Open();
try
{
IDbCommand myCommand = myConnection.CreateCommand();
myCommand.CommandText = "LOCK TABLES tagml_action READ";
myCommand.ExecuteNonQuery();

myCommand = myConnection.CreateCommand();
// Causes scan instead of seek for now
myCommand.CommandText = "SELECT ActionId,TypeId,TableId,TableIndex FROM tagml_action WHERE WorkspaceId=?workspace AND ActionId>?actionid";

IDbDataParameter p = myCommand.CreateParameter();
p.ParameterName = "?workspace";
p.Value = workspaceId;
AddDbTypeToParameter(myCommand, p);

p = myCommand.CreateParameter();
p.ParameterName = "?actionid";
p.Value = lastActionId;
AddDbTypeToParameter(myCommand, p);

IDataReader reader = myCommand.ExecuteReader();
while(reader.Read())
{
Action newAction = new Action();
newAction.ActionId = (Int64)reader["ActionId"];
newAction.ActionType = (ActionTypeEnums)(Int16)reader["TypeId"];
newAction.Table = (TableEnums)(Int16)reader["TableId"];
newAction.TableIndex = (UInt32)reader["TableIndex"];

newActionList.Add(newAction);
}
reader.Close();

myCommand = myConnection.CreateCommand();
myCommand.CommandText = "UNLOCK TABLES";
myCommand.ExecuteNonQuery();
}
catch(Exception e)
{
myConnection.Close();
throw e;
}
myConnection.Close();

return (Action[])newActionList.ToArray(typeof(Action));
}

Options: ReplyQuote


Subject
Written By
Posted
January 26, 2005 11:05AM
Re: Garbage Collection in .NET?
January 27, 2005 05:42PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.