From: Thomas <ja...@ma...> - 2003-12-19 11:26:28
|
Now and then we get an exception in "BeginTrancaction". When I call BeginTransaction(), then I get this error: at FirebirdSql.Data.Firebird.Gds.GdsTransaction.BeginTransaction() at FirebirdSql.Data.Firebird.FbTransaction.BeginTransaction() at FirebirdSql.Data.Firebird.FbConnection.BeginTransaction() (That is all the info that I get) Some times the exception arise after 5 minutes, and some times the = exception arise after 30 hours. Very very random. It is very hard to re-create the error, but it is 100% sure that the = error arise at some point. In my program, I call "myConnection.BeginTransaction()" once every 3 = second. (Many hours). We use: WinXP SP1 FirebirdSql.Data.Firebird.dll v. 1.5.1437.22333 (.NET 1.1) Firebird-1.5.0.4027-RC7, running af Super Server. Microsoft .NET Framework 1.1 v. 1.1.4322 Hope that you can help me with this problem. Thanks Regards Thomas /// Code snip////// (It is impossible to send the full code) My Connection Class that is a singleton: ........................ private FbConnection myConnection; public static Connection Instance { get { =20 if(instance =3D=3D null) { instance =3D new Connection(); =20 }//if return instance; }//get property }//property get instance of Connection =20 //constructor private Connection() { try { myConnectionString =3D getURLToDB(); myConnection =3D new FbConnection(myConnectionString); =20 openConnection(); }//try catch (Exception ex) { string t =3D ex.Message; string t2 =3D ex.StackTrace; = BusinessComponents.LogToFile.Instance.logALineToFile(ex.ToString(),true);= }//try/catch }//constructor =20 =20 =20 public bool updateTransaction(string myUpdateQuery) { try { myConnection =3D MyConnection; transaction =3D myConnection.BeginTransaction(); myCommandOne =3D new FbCommand(myUpdateQuery, myConnection, = transaction);=20 myCommandOne.ExecuteNonQuery(); transaction.Commit(); myCommandOne.Dispose(); } catch(Exception eb) { =20 =20 = BusinessComponents.LogToFile.Instance.logALineToFile(eb.StackTrace,true);= BusinessComponents.LogToFile.Instance.logALineToFile("This = SQL-statement was not saved in the database: " + myUpdateQuery,false); string t =3D eb.StackTrace; transaction.Rollback(); transaction.Dispose(); closeConnection(); openConnection(); throw eb; }//try/catch return true; }//updateTransaction =20 =20 =20 public void closeConnection() { try { if (myConnection.State !=3D System.Data.ConnectionState.Closed) { myConnection.Close(); =20 }//if }//try catch (Exception ex) { =20 = BusinessComponents.LogToFile.Instance.logALineToFile(ex.ToString(),true);= =20 Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); }//try/catch }//closeConnection =20 =20 public void openConnection() { try { if (myConnection.State !=3D System.Data.ConnectionState.Open) { myConnection.Open(); }//if }//try catch(Exception ex) { =20 = BusinessComponents.LogToFile.Instance.logALineToFile(ex.ToString(),true);= =20 Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); }//try/catch }//openConnection =20 =20 public FbConnection MyConnection { get { =20 try { if (this.connectionCounter > 500) { if (this.myConnection !=3D null) { myConnection.Dispose(); myConnection =3D new FbConnection(myConnectionString); openConnection(); this.connectionCounter =3D 0; }//if }//if =20 else { =20 if (this.myConnection !=3D null) { closeConnection(); }//if openConnection(); this.connectionCounter =3D this.connectionCounter+1; }//else =20 }//try catch (Exception ex) { =20 = BusinessComponents.LogToFile.Instance.logALineToFile(ex.ToString(),true);= =20 }//try/catch return this.myConnection; }//get =20 }//property myConnection =20 =20 =20 |
From: Thomas <ja...@ma...> - 2003-12-19 21:25:05
|
Hi Carlos Now I have re-created the problem. This log line:=20 Console.WriteLine(eb.Message + " - " + eb.Source + " - " + eb.StackTrace = + " - " + eb.InnerException); prints this message: 21:54:56.140 - Message: Object reference not set to an instance of an = object. - Stacktrace: at = FirebirdSql.Data.Firebird.Gds.GdsTransaction.BeginTransaction() at = FirebirdSql.Data.Firebird.FbTransaction.BeginTransaction() at = FirebirdSql.Data.Firebird.FbConnection.BeginTransaction() at = Tricon.Funki.PDBServer.DataAccessLogicComponents.LoadStatements.loadAllSc= aleHavePipe() in = c:\vss\funki\pdbserver\tricon.funki.pdbserver\dataaccesslogiccomponents\l= oadstatements.cs:line 2509 - Source: FirebirdSql.Data.Firebird - = InnerException: (The InnerException is empty.) In this test case, the same code runs 288 times. In loop 289 the exception arised. My code: (loadAllScaleHavePipe() failed in loop no. 289.) public Hashtable loadAllScaleHavePipe() { ScaleHavePipe scalehavepipe =3D null; Hashtable HT =3D new Hashtable(); =20 myConnection =3D Connection.Instance.MyConnection; mySelectQuery =3D "SELECT * FROM scalehavepipe"; try { =20 transaction =3D myConnection.BeginTransaction(); <---- ERROR ? myCommand =3D new FbCommand(mySelectQuery, myConnection, = transaction); =20 myReader =3D myCommand.ExecuteReader(); =20 while (myReader.Read()) { scalehavepipe =3D new = ScaleHavePipe((int)myReader["id"],(int)myReader["scaletype"], (int)myReader["scale_id"],(int)myReader["pipe_id"]); HT.Add(scalehavepipe.Id, scalehavepipe); }//while myReader.Close();=20 transaction.Commit(); } catch(Exception eb) { =20 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 =3D (FbException)eb; =20 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 =3D=3D 0) { = BusinessComponents.LogToFile.Instance.logALineToFile("myException.Errors.= Count is 0 ",true); } for (int i=3D0; i < myException.Errors.Count; i++) { =20 BusinessComponents.LogToFile.Instance.logALineToFile("Index #" + i = + "\n" +"Error: " + myException.Errors[i].ToString() + "\n",true); =20 } =20 } else { =20 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); } Connection.Instance.closeConnection(); Connection.Instance.openConnection(); throw eb; }//try/catch return HT; }//loadAllScaleHavePipe =20 =20 =20 =20 public FbConnection MyConnection { get { =20 try { if (this.connectionCounter > 500) { if (this.myConnection !=3D null) { myConnection.Dispose(); myConnection =3D new FbConnection(myConnectionString); openConnection(); this.connectionCounter =3D 0; }//if }//if =20 else { =20 if (this.myConnection !=3D null) { closeConnection(); }//if openConnection(); this.connectionCounter =3D this.connectionCounter+1; }//else =20 }//try catch (Exception eb) { =20 =20 if (eb is FbException) { FbException myException =3D (FbException)eb; =20 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 =3D=3D 0) { = BusinessComponents.LogToFile.Instance.logALineToFile("myException.Errors.= Count is 0 ",true); } for (int i=3D0; i < myException.Errors.Count; i++) { =20 BusinessComponents.LogToFile.Instance.logALineToFile("Index #" = + i + "\n" +"Error: " + myException.Errors[i].ToString() + "\n",true); = =20 } =20 } else { =20 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); } =20 }//try/catch return this.myConnection; }//get =20 }//property myConnection I cannot see why a "Object reference not set to an instance of an = object" should come after 288 loops. Thanks Regards Thomas -------------------------------------------------------------------------= -------------------------------------------------------------------------= -------------------------------------------------------- Now and then we get an exception in "BeginTrancaction". When I call BeginTransaction(), then I get this error: at FirebirdSql.Data.Firebird.Gds.GdsTransaction.BeginTransaction() at FirebirdSql.Data.Firebird.FbTransaction.BeginTransaction() at FirebirdSql.Data.Firebird.FbConnection.BeginTransaction() (That is all the info that I get) Some times the exception arise after 5 minutes, and some times the = exception arise after 30 hours. Very very random. It is very hard to re-create the error, but it is 100% sure that the = error arise at some point. In my program, I call "myConnection.BeginTransaction()" once every 3 = second. (Many hours). We use: WinXP SP1 FirebirdSql.Data.Firebird.dll v. 1.5.1437.22333 (.NET 1.1) Firebird-1.5.0.4027-RC7, running af Super Server. Microsoft .NET Framework 1.1 v. 1.1.4322 Hope that you can help me with this problem. Thanks Regards Thomas /// Code snip////// (It is impossible to send the full code) My Connection Class that is a singleton: ........................ private FbConnection myConnection; public static Connection Instance { get { =20 if(instance =3D=3D null) { instance =3D new Connection(); =20 }//if return instance; }//get property }//property get instance of Connection =20 //constructor private Connection() { try { myConnectionString =3D getURLToDB(); myConnection =3D new FbConnection(myConnectionString); =20 openConnection(); }//try catch (Exception ex) { string t =3D ex.Message; string t2 =3D ex.StackTrace; = BusinessComponents.LogToFile.Instance.logALineToFile(ex.ToString(),true);= }//try/catch }//constructor =20 =20 =20 public bool updateTransaction(string myUpdateQuery) { try { myConnection =3D MyConnection; transaction =3D myConnection.BeginTransaction(); myCommandOne =3D new FbCommand(myUpdateQuery, myConnection, = transaction);=20 myCommandOne.ExecuteNonQuery(); transaction.Commit(); myCommandOne.Dispose(); } catch(Exception eb) { =20 =20 = BusinessComponents.LogToFile.Instance.logALineToFile(eb.StackTrace,true);= BusinessComponents.LogToFile.Instance.logALineToFile("This = SQL-statement was not saved in the database: " + myUpdateQuery,false); string t =3D eb.StackTrace; transaction.Rollback(); transaction.Dispose(); closeConnection(); openConnection(); throw eb; }//try/catch return true; }//updateTransaction =20 =20 =20 public void closeConnection() { try { if (myConnection.State !=3D System.Data.ConnectionState.Closed) { myConnection.Close(); =20 }//if }//try catch (Exception ex) { =20 = BusinessComponents.LogToFile.Instance.logALineToFile(ex.ToString(),true);= =20 Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); }//try/catch }//closeConnection =20 =20 public void openConnection() { try { if (myConnection.State !=3D System.Data.ConnectionState.Open) { myConnection.Open(); }//if }//try catch(Exception ex) { =20 = BusinessComponents.LogToFile.Instance.logALineToFile(ex.ToString(),true);= =20 Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); }//try/catch }//openConnection =20 =20 public FbConnection MyConnection { get { =20 try { if (this.connectionCounter > 500) { if (this.myConnection !=3D null) { myConnection.Dispose(); myConnection =3D new FbConnection(myConnectionString); openConnection(); this.connectionCounter =3D 0; }//if }//if =20 else { =20 if (this.myConnection !=3D null) { closeConnection(); }//if openConnection(); this.connectionCounter =3D this.connectionCounter+1; }//else =20 }//try catch (Exception ex) { =20 = BusinessComponents.LogToFile.Instance.logALineToFile(ex.ToString(),true);= =20 }//try/catch return this.myConnection; }//get =20 }//property myConnection =20 =20 =20 |
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 } } |
From:
<car...@te...> - 2003-12-19 11:42:00
|
Hello: > Now and then we get an exception in "BeginTrancaction". > > When I call BeginTransaction(), then I get this error: > > > at FirebirdSql.Data.Firebird.Gds.GdsTransaction.BeginTransaction() > at FirebirdSql.Data.Firebird.FbTransaction.BeginTransaction() > at FirebirdSql.Data.Firebird.FbConnection.BeginTransaction() What is the Exception message :) ?? Can you change your log code for anything like this: BusinessComponents.LogToFile.Instance.logALineToFile(ex.Message,true); or BusinessComponents.LogToFile.Instance.logALineToFile( ex.Message + "\r\n" + ex.StackTrace + "\r\n" + ex.Source, true); FbException class has two properties that can be of help: - ErrorCode ( main error code sent by the Firebird Server if the inner exception is GdsException ) - Errors ( list of individual errors received from the Firebird Server if inner exception is GdsException ) -- Best regards Carlos Guzmán Álvarez Vigo-Spain |