From:
<car...@te...> - 2003-12-19 22:31:26
|
Hello: > Now I have re-created the problem. Thanks very much. At the end of this email is the sample i am going to use for test this, based on the test case you have sent, tell to me if you think that it's not correct. Note that i have added this code: finally { if (myCommand != null) { myCommand.Dispose(); myCommand = null; } } to loadAllScaleHavePipe() for Dispose the command resources. I have noticed too that in loadAllScaleHavePipe() when an exception occurs you closing and opening the connection, any special reason for this ?? ( i am curious :) ) -- Best regards Carlos Guzmán Álvarez Vigo-Spain using System; using System.Collections; using System.Data; using FirebirdSql.Data.Firebird; namespace FirebirdSql.Data.Firebird { public class Test { private int connectionCounter; private string myConnectionString; private FbConnection myConnection; private FbTransaction transaction; private FbDataReader myReader; private FbCommand myCommand; public Test() { myConnectionString = @"Database=localhost/3050:TEST.FDB;" + "User=SYSDBA;" + "Password=masterkey;" + "Dialect=3;" + "Charset=NONE;" + "Pooling=true;" + "Connection Lifetime=30;" + "Role=;"; } public static void Main(string[] args) { Test t = new Test(); for (int i = 0; i < 10000; i++) { t.loadAllScaleHavePipe(); } } public Hashtable loadAllScaleHavePipe() { // ScaleHavePipe scalehavepipe = null; Hashtable HT = new Hashtable(); myConnection = this.MyConnection; string mySelectQuery = "SELECT * FROM updates"; try { transaction = myConnection.BeginTransaction(); myCommand = new FbCommand( mySelectQuery, myConnection, transaction); myReader = myCommand.ExecuteReader(); while (myReader.Read()) { /* scalehavepipe = new ScaleHavePipe((int)myReader["id"],(int)myReader["scaletype"], (int)myReader["scale_id"],(int)myReader["pipe_id"]); HT.Add(scalehavepipe.Id, scalehavepipe); */ }//while myReader.Close(); transaction.Commit(); } catch(Exception eb) { Console.WriteLine(eb.Message + " - " + eb.Source + " - " + eb.StackTrace + " - " + eb.InnerException); // BusinessComponents.LogToFile.Instance.logALineToFile(eb.Message + " - " + eb.Source + " - " + eb.StackTrace + " - " + eb.InnerException,true); if (eb is FbException) { FbException myException = (FbException)eb; // BusinessComponents.LogToFile.Instance.logALineToFile("This is a FbException: Message: "+myException.Message + " - Stacktrace: " + myException.StackTrace + " - Source: " +myException.Source + " - InnerException:" + myException.InnerException + " - ErrorCode: " + myException.ErrorCode,true); Console.WriteLine("This is a FbException: Message: "+myException.Message + " - Stacktrace: " + myException.StackTrace + " - Source: " +myException.Source + " - InnerException:" + myException.InnerException + " - ErrorCode: " + myException.ErrorCode); if (myException.Errors.Count == 0) { // BusinessComponents.LogToFile.Instance.logALineToFile("myException.Errors.Count is 0 ",true); } for (int i=0; i < myException.Errors.Count; i++) { // BusinessComponents.LogToFile.Instance.logALineToFile("Index #" + i + "\n" +"Error: " + myException.Errors[i].ToString() + "\n",true); } } else { // BusinessComponents.LogToFile.Instance.logALineToFile("Message: "+eb.Message + " - Stacktrace: " + eb.StackTrace + " - Source: " +eb.Source + " - InnerException:" + eb.InnerException,true); Console.WriteLine("Message: "+eb.Message + " - Stacktrace: " + eb.StackTrace + " - Source: " +eb.Source + " - InnerException:" + eb.InnerException); } myConnection.Close(); myConnection.Open(); throw eb; }//try/catch finally { if (myCommand != null) { myCommand.Dispose(); myCommand = null; } } return HT; }//loadAllScaleHavePipe public FbConnection MyConnection { get { try { if (this.connectionCounter > 500) { if (this.myConnection != null) { myConnection.Dispose(); myConnection = new FbConnection(myConnectionString); myConnection.Open(); this.connectionCounter = 0; }//if }//if else { if (this.myConnection != null) { myConnection.Close(); }//if myConnection.Open(); this.connectionCounter = this.connectionCounter+1; }//else }//try catch (Exception eb) { if (eb is FbException) { FbException myException = (FbException)eb; // BusinessComponents.LogToFile.Instance.logALineToFile("This is a FbException: Message: "+myException.Message + " - Stacktrace: " + myException.StackTrace + " - Source: " +myException.Source + " - InnerException:" + myException.InnerException + " - ErrorCode: " + myException.ErrorCode,true); Console.WriteLine("This is a FbException: Message: "+myException.Message + " - Stacktrace: " + myException.StackTrace + " - Source: " +myException.Source + " - InnerException:" + myException.InnerException + " - ErrorCode: " + myException.ErrorCode); if (myException.Errors.Count == 0) { // BusinessComponents.LogToFile.Instance.logALineToFile("myException.Errors.Count is 0 ",true); } for (int i=0; i < myException.Errors.Count; i++) { // BusinessComponents.LogToFile.Instance.logALineToFile("Index #" + i + "\n" +"Error: " + myException.Errors[i].ToString() + "\n",true); } } else { // BusinessComponents.LogToFile.Instance.logALineToFile("Message: "+eb.Message + " - Stacktrace: " + eb.StackTrace + " - Source: " +eb.Source + " - InnerException:" + eb.InnerException,true); Console.WriteLine("Message: "+eb.Message + " - Stacktrace: " + eb.StackTrace + " - Source: " +eb.Source + " - InnerException:" + eb.InnerException); } }//try/catch return this.myConnection; }//get }//property myConnection } } |