How long are you keeping connections opened? Are you passing open
connection around? What about only opening the connection when you need it.
Are you worried about conforming to the ACID rules for databases? Then I
would suggest using a transaction.
using (OracleConnection conn = new OracleConnection(_connString))
{
using (OracleCommand cmd = new OracleCommand("select * from
cidb.msg_hdr some_table", conn))
{
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
using (OracleDataReader rdr =
cmd.ExecuteReader(CommandBehavior.CloseConnection |
CommandBehavior.SingleRow))
{
Debug.Assert(conn != null, "connection is null");
Debug.Assert(conn.State ==
ConnectionState.Open, "connection is closed");
while (rdr.Read())
{
//do something with the rdr
} //end while read()
} //end using reader
} //end using
} //end using
--Fran
-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Eduard Lascu
Sent: Wednesday, April 13, 2005 9:20 AM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] State of a database connection
Ido,
That property is implemented by the OracleConnection class too (which
inherits IDbConnection interface). The problem is that the property is not
internally updated. It will change from ConnectionState.Open to
ConnectionState.Close and the other way around only when the user calls Open
and Close on the connection object.
I need something to tell me that the connection has gone down when I try to
use it.
If the connection was opened, the State will stay ConnectionState.Open until
I call Close on the connection object. Meantime, the physical connection can
be interrupted by some external conditions, and there is no way I can tell
that.
I hope I was clearer this time.
Thanks,
Eddie
-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] Behalf Of עידו שמואלסון
Sent: Wednesday, April 13, 2005 5:15 AM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] State of a database connection
In System.Data.IDbConnection check the State property. This return the
System.Data.ConnectionState enum.
Best Regards,
Ido Samuelson
Senior Consultant
Magen - Microsoft Technology Center
-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Eduard Lascu
Sent: Tuesday, April 12, 2005 9:58 PM
To: [email protected]
Subject: [ADVANCED-DOTNET] State of a database connection
I recently ran into a problem trying to figure out what is the state of my
Oracle database connection object (I refer to Oracle specific classes, but I
assume it's the same throughout the entire Framework Class Library).
When I get the OracleConnection.State property I obtain ConnectionState.Open
even when the connection has actually gone down recently. Executing a
command will raise an exception, but I need to check the state of the
connection before I go to execute the command.
I guess something like the old CDatabase::IsOpen would be great.
Did anyone here have implemented an IsDatabaseOpen method that will check
the state of the connection?
I could issue a dummy SQL statement, such as "select sysdate from dual" or
something inside the IsDatabaseOpen method, but I noticed that the error
raised can have a different code whether you disable the local network,
unplug the cable or just reboot the database server. I checked all the
methods offered in the interface and there is little to use to create this
functionality.
Any idea would be great.
TIA
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
------------------------------------------------------------------------------
Notice: This e-mail message, together with any attachments, contains
information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station, New
Jersey, USA 08889), and/or its affiliates (which may be known outside the
United States as Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as
Banyu) that may be confidential, proprietary copyrighted and/or legally
privileged. It is intended solely for the use of the individual or entity named
on this message. If you are not the intended recipient, and have received this
message in error, please notify us immediately by reply e-mail and then delete
it from your system.
------------------------------------------------------------------------------
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com