PC Review


Reply
Thread Tools Rate Thread

Connection closed

 
 
Mark
Guest
Posts: n/a
 
      17th Mar 2004
Using ASP.Net to read/write to an Access DB on a webserver.
How can I check to make sure I haven't left any connections open ? I
have physical access to the server if I need to check it there. I really
want to verify all is well before I go live with it.

Thanks,
Mark


 
Reply With Quote
 
 
 
 
Scott M.
Guest
Posts: n/a
 
      17th Mar 2004
The connection object has a ConnectionState property (or something to that
effect). It can be used to determine if the connection is open or not.

If you are not sure, you can call the Close method (and you should be doing
this when your code is done with the connection) a second time. It will not
throw an exception even if the connection was already closed.

Also, be aware that ADO.NET connections use connection pooling, so even
though your connection may be closed it will still exist (in a closed state)
in the pool in case some other bit of code needs to use it again.


"Mark" <(E-Mail Removed)> wrote in message
news:uhPa$(E-Mail Removed)...
> Using ASP.Net to read/write to an Access DB on a webserver.
> How can I check to make sure I haven't left any connections open ? I
> have physical access to the server if I need to check it there. I really
> want to verify all is well before I go live with it.
>
> Thanks,
> Mark
>
>



 
Reply With Quote
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      17th Mar 2004
Apart from the Scott's good reply I would suggest you to embedd Open/Close
into try/finally statement.

conn.Open();
try
{
...
}
finally
{
conn.Close();
}

Also, connection implements IDisposable, thus you might call it at the end
(even if it does nothing - it could do something in the future).
Btw, Dispose also closes connection:

using (OleDbConnection conn = new OleDbConnection(...))
{
}

Is enough to sleep well.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com


"Mark" <(E-Mail Removed)> wrote in message
news:uhPa$(E-Mail Removed)...
> Using ASP.Net to read/write to an Access DB on a webserver.
> How can I check to make sure I haven't left any connections open ? I
> have physical access to the server if I need to check it there. I really
> want to verify all is well before I go live with it.
>
> Thanks,
> Mark
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB.NET application cliick-once deployment via internet - Error - Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. Peri Microsoft VB .NET 2 29th Feb 2008 09:46 AM
ExecuteReader requires an open and available Connection. The connection's current state is Closed. renu renu via .NET 247 Microsoft ADO .NET 1 23rd Jan 2005 09:40 PM
ExecuteReader requires an open and available Connection. The connection's current state is Closed. renu renu via .NET 247 Microsoft ADO .NET 1 23rd Dec 2004 01:23 PM
ExecuteReader requires an open and available Connection. The connection's current state is Closed. renu renu via .NET 247 Microsoft ADO .NET 1 1st Nov 2004 03:33 PM
ExecuteReader requires an open and available Connection. The connection's current state is Closed. renu renu via .NET 247 Microsoft ADO .NET 1 17th Oct 2004 02:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:51 PM.