J
Jack Wright
Dear All,
We are facing problem for OleDBConnection if my connection to database
is killed or database server is restarted.
it gives error:
System.Data.OleDb.OleDbException: Session closed/terminated
Problem:
1. For executing SQL query we create new OleDBConnection, execute
that query and then instead of closing that connection,
we put that connection object in static arrayList
(freeConnectionList).
2. For next SQL query, it checks in that static arraylist for free
connection, if it gets any free connection, then uses that
connection object for executing query, else if it cannot find any
free connection in this arraylist, it creates new connection,
executes query and then add that connection in arraylist.
3. It works fine. But problem comes if my database session is killed
OR database is re-started.
4. if my database session is killed OR database is re-start, and I try
to fire query using connection object that is
there in static arraylist or using new OleDBConnection object, then
it generates error.
So if my database session is killed or database is restarted, then
1. I cannot use connection objects from static arraylist
2. and if I create new Connection object, then that new connection
object also fails to fire query.
Solution:
1. If my dadatabse session is killed or database is restarted, and I
try to fire a query, then it throws OleDBException, We will catch that
exception,
then then we will close all the connection from arraylist. For
this the code will be like this:
Pseudo Code:
public void ResetPool()
{
OleDBConnection dummyConnection = new OleDBConnection(connString);
// declare a dummy connection
dummyConnection.Open(); // open dummy connection
int i = freeConnectionList.Count-1;
while ( i >= 0 )
{
freeConnectionList.Close(); // close connection
i--;
}
dummyConnection.Close(); // close dummy connection
}
For this I have to create a dummy connection, open that connection and
then close that connection at the end when all connections from
arraylist are closed.
If I do these changes then it works fine.
Query:
Is this a correct method to handle situaton like database restart or
database session killed? OR there is any alternative way of doing the
same?
Thanx and Regards
Jack
We are facing problem for OleDBConnection if my connection to database
is killed or database server is restarted.
it gives error:
System.Data.OleDb.OleDbException: Session closed/terminated
Problem:
1. For executing SQL query we create new OleDBConnection, execute
that query and then instead of closing that connection,
we put that connection object in static arrayList
(freeConnectionList).
2. For next SQL query, it checks in that static arraylist for free
connection, if it gets any free connection, then uses that
connection object for executing query, else if it cannot find any
free connection in this arraylist, it creates new connection,
executes query and then add that connection in arraylist.
3. It works fine. But problem comes if my database session is killed
OR database is re-started.
4. if my database session is killed OR database is re-start, and I try
to fire query using connection object that is
there in static arraylist or using new OleDBConnection object, then
it generates error.
So if my database session is killed or database is restarted, then
1. I cannot use connection objects from static arraylist
2. and if I create new Connection object, then that new connection
object also fails to fire query.
Solution:
1. If my dadatabse session is killed or database is restarted, and I
try to fire a query, then it throws OleDBException, We will catch that
exception,
then then we will close all the connection from arraylist. For
this the code will be like this:
Pseudo Code:
public void ResetPool()
{
OleDBConnection dummyConnection = new OleDBConnection(connString);
// declare a dummy connection
dummyConnection.Open(); // open dummy connection
int i = freeConnectionList.Count-1;
while ( i >= 0 )
{
freeConnectionList.Close(); // close connection
i--;
}
dummyConnection.Close(); // close dummy connection
}
For this I have to create a dummy connection, open that connection and
then close that connection at the end when all connections from
arraylist are closed.
If I do these changes then it works fine.
Query:
Is this a correct method to handle situaton like database restart or
database session killed? OR there is any alternative way of doing the
same?
Thanx and Regards
Jack