What could cause left open SQL data connection

G

Guest

Hi just wondering what could cause a left open SQL connection as this has only occured 2 times in the last week. The error it creates is when a web app tries to open a connection an error message states, it is already open. The process was then killed to close the connection. The usage is pretty low around 15 workstations. Looking at the code it appears that all connections get closed, so thinking it is not a problem with the code. Thanks Paul.
 
S

Scott M.

Are you calling the .close method of the connection or just killing the
process? Killing the process won't close the ADO.NET SQLConnection object.

You should have your .open method in a Try...Catch and the .close method in
the Finally.


Paul said:
Hi just wondering what could cause a left open SQL connection as this has
only occured 2 times in the last week. The error it creates is when a web
app tries to open a connection an error message states, it is already open.
The process was then killed to close the connection. The usage is pretty
low around 15 workstations. Looking at the code it appears that all
connections get closed, so thinking it is not a problem with the code.
Thanks Paul.
 
W

William Ryan eMVP

Paul...

if you have this code


myConnection.Open();
int i = myCommand.ExecuteScalar();
myConnection.Close
and you raise an exception, you'll never hit close so I'd check that first,
and move my close statements to Finally blocks. I'm guessing that's the
problem. If not, let me know.

Bill
Paul said:
Hi just wondering what could cause a left open SQL connection as this has
only occured 2 times in the last week. The error it creates is when a web
app tries to open a connection an error message states, it is already open.
The process was then killed to close the connection. The usage is pretty
low around 15 workstations. Looking at the code it appears that all
connections get closed, so thinking it is not a problem with the code.
Thanks Paul.
 
K

Kevin Spencer

It's definitely a problem with the code. It sounds like some developer is
playing around with re-using Connections in your app. Not a good practice in
..Net.

General rule of thumb: Open a Connection when you need it, use it, Close it
as soon as you're done with it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Paul said:
Hi just wondering what could cause a left open SQL connection as this has
only occured 2 times in the last week. The error it creates is when a web
app tries to open a connection an error message states, it is already open.
The process was then killed to close the connection. The usage is pretty
low around 15 workstations. Looking at the code it appears that all
connections get closed, so thinking it is not a problem with the code.
Thanks Paul.
 
K

Kevin Spencer

Didn't think of that! Excellent suggestion!

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
C

Chad Crowder

Agreed. I read that post and was like, holy cow I need to check my code!

Thanks Bill!

- Chad
 
G

Guest

ok thanks for the responses. This is code that someone else developed and I have modified
I did add a section of code that uses a data connection, data adapter, and a dataset. It calls a stored procedure on the server. I did not use open or close in the code but it seemed to be working ok. The stored procedure pulls data from a few tables and displays it on the data grid
Do I need to implicitly use the open and close statements for the connection or data adapter for this or does the fill automatically open the connection and then close it

SqlDataAdapter1.Fill(ds_vhist, "dbo_pg_parmsel_past_reservation"
Vhistgrid.DataBind(

Thank
Paul.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top