Database connection is not closed

Hello,

I have a class getData.vb.  In the new method of the class, I open an new connection to the database. From each page on load event, when I need to get data from database, I dim _getData as new getData, and at the end of page load I have a Finally _getData.dispose.  In the dispose module, I close the database connection. In the getData class, I have a function which returns a dataReader. Of course, when I create a new data reader, I create a new connection. When I need the data reader from page, I have the code dr = _getData.getDataReader, after I use it. I close the data reader with dr.close  and dr = nothing.

I think I closed the database connection, when I did above.  But actually, all the connections are still there. When I excuate sp_who from SQL, I can see all of the connections. After a while on my web site, I got the error, because it reached the max pool size. 

And sometimes,  when I try to grab more data using _getData.getDataset.  I got the error. I think it is because when the connection created in _getData new is idel, the data reader took it from the connection pool. So the connection associated with _getData is not available any more.

I do not know, if other people encounter the same problem.  How come my connections are not closed most of the time and not available when I need it.

Please help!

Mei 

 

 

 

 

0
bruceq
4/21/2007 6:30:30 AM
asp.net.object-datasource 16182 articles. 0 followers. Follow

6 Replies
443 Views

Similar Articles

[PageSpeed] 25

Hi,

Use delegates in your code. Read the following articles

http://aspalliance.com/526

http://aspalliance.com/articleViewer.aspx?aId=626&pId=-1

 

HTH 


ASP.NET Hosting (HostingFest)
0
smiling4ever
4/21/2007 8:03:44 AM
Hi, thanks for your reply. I will try the delegates.  But I still do not understand why after I call connection.close, the connection is still there.  Even if I closed the borwser.  I still see lot of connections using sp_who in SQL
0
bruceq
4/21/2007 6:10:08 PM
The articles i mentioned above explain everything about your issue, just take a look on them.

ASP.NET Hosting (HostingFest)
0
smiling4ever
4/21/2007 9:23:16 PM

Hi,

This is because of the connection pooling. After you close the connection object, the underlying connection will be returned to the pool and is kept open for some time. The pool will maintain the status of them automatically.

This will help improve performance when you have an app that is always opening and closing frequently.

You can surely disable it by adding pooling=false in your connection string.

HTH. If this does not answer your question, please feel free to mark the post as Not Answered and reply. Thank you!


Sincerely,
Kevin Yu
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Mark as Not Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
0
Kevin
4/23/2007 7:18:59 AM
I can not set pooling=false. Because my application is not the only one on the web server.
0
bruceq
4/23/2007 3:55:01 PM

bruceq:
I can not set pooling=false. Because my application is not the only one on the web server.

This will affect your application only since it is in your connectionstring. 


ASP.NET Hosting (HostingFest)
0
smiling4ever
4/23/2007 6:57:30 PM
Reply:

Similar Artilces:

During connection lost, how to close database connection
I'm using TidTCPServer OnExecute method. When client connect to server, I create Database connection with Unidac to PostGreSQL (connection ceated and handled inside onExecute). Problem is when the connection to client is lost, the connection to database does'nt disappear. When cheking from PostGRE pgAdmin there is several connections more than what we have clients. I have tried to put dbConnect.close or FreeandNil(dbConnect) or dbConnect.Free in try.. except.. end except block. But it looks like when the connection is lost, the thread stop/collaps and the database connection stay...

Connection.close() not closing my connection?
My servlet calls con.close() within the finally {} of a try..catch block. Yet I notice that sa_conn_info still lists the connection. Shouldn't the connection disappear from the sa_conn_info list when I close it? And if the answer to that is "yes, it should", has anybody seen situations like mine where it *doesn't* close it? Thanks for your help, Kathleen My bad... through a series of really stupid coding mistakes, I managed to cause a SQLException to be thrown from within the finally {} block before the connection could be closed... and I was ignoring the ...

Timeout connecting with .NET connection object
I have a SQL Anywhere 9 database that I can connect to fine via Sybase Central or ISQL. However, when I attempt to connect using the AsaConnection object from the IAnywhere.Data.AsaClient namespace, the open connection call times out. The code works fine on my development box, but I cannot get the connection to work on the production box. Any ideas? Thanks, David ...

how to close database connection, connection pool issue
I have create a asp.net 2.0 application with mysql using the .net/connector 5.1. Most of my pages use a ObjectDataSource control and a Repeater Control. I am calling Close() on both the reader and DB connection but it appears that the connections are not closing and the connection pool gets filled up and I get an error. Does anyone know why the connections aren't closing?  Heres the function that the ObjectDataSource calls:Function myFunc(ByVal subCat As String, ByVal sortBy As String) Dim connStr As String = ConfigurationManager.ConnectionStrings("connector").Co...

close window appliation without connection close of database
 Hello,If i close window application without connection close of database, connection will be closed or it is still there in pool?Thanks VISHAL PAREKH vrparekh@gmail.com:  Hello, If i close window application without connection close of database, connection will be closed or it is still there in pool? Thanks It will be alive unless you close it using Connection.Close()  MAKMark as Answer if this reply helps youMVP ASP/ASP.NetASP.Net Hosting : Host DepotMy Site : ASPSnippets vrparekh@gmail.com:If i close window application without connection close of database, co...

Database Connection???How to connect a Database in an other server?
How to connect a Database(.mdb) in an other server? Can I use the connection string like below? mycon.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=http://www.****.com/***/mydb.mdb" You can not. That simple. Access is file based. No a client/server architecture.Thomas TomiczekPowerNodes ApS(Microsoft MVP C#/.NET)---Building a Website? Try the PowerNodes CMS - http://www.powernodes.com/ Correction: you can. Just make sure you can reach the acces db file - through a file share that is bound as drive. Not that you should. Performance will be horrib...

Closing database connections
I found an article on closing database connections in the finally section of a try block.  This works for everything I have tried except for the database functions that return a data reader.  When I close those I am unable to do a "while rdr.read" command.  What is the most efficient way to close those? Thank you. Try catch finally is for operations where you expect an exception. In the finally block you clean up what might be left. So if you close the connection, after that, you cannot read from the database (as you have noticed). You can try to read everything i...

How to close database connection
HI guys, I have the following code that instantiates my data layer and connect to the database. I then retun the DataSet back to the codebehind. When/Where do I close the database connection? If I close the connection on the datalayer my codebehind gives me 'connection is closed' errors. So.. where do I close the connection? THanks! --- users.aspx.vb --- Dim allUsers As New XYZ.adminDim userDataTable As New DataSetuserDataTable = allUsers.GetUsers() do what i need to with userDataTableblahblah --- admin.vb --- Public Function GetUsers() As DataSet''Create a connection to the datab...

Database connection does not close?!?
Okay. I think I have tolerated this long enough. At first it was just a little annoyance, now it completely ticks me off and is taking up too much of my time. Whenever I use a OledbDataReader on a page, it locks up my MS Access Database with a .lbd file. I use a DataHandler vb page for calling my function for using the datareader. Here is the function within my DataHandler: Public Shared Function GetDataReader(ByVal strSQL As String, ByVal strConn As String) As OleDbDataReader Dim dr As OleDbDataReader Dim cmd As New OleDbCommand With cmd .Connection = New OleDbConnection(strConn) .C...

Close the Database Connection
Hi, I want a DB connection to remain open as long as my application is running, and close when my application exits. Is there any OnExit event that I can call anywhere and have the connection close in there ? Thanks, -Apurva. Application_OnEnd Application_OnEnd is raised only once during an application's lifetime, on the last instance of HttpApplication that is torn down. Use Application_OnEnd only to clean up states or resources shared by all pipeline instances, such as the use of the ApplicationState object, or in your case, database resources. You'll want to add this call...

closing all database connections
Hi, I'm using a SQL database for my project in c#. At the moment I'm building a page where you can backup the database. But I always get the error that the database is in use when I test it online (some people already use the project). Is there any way to close ALL connections and not only mine. At the moment this I have:   string connectionStringName = ConfigurationManager.AppSettings["connectionStringName"]; Database _db = PIHBE.Data.Common.Database.GetInstance(connectionStringName); _db.Close(); _db.Dispose(); _db.ClearAllPools(); int iVersion = GetVersion(sPath, sDa...

How to close a connection to the database
Is there any way to close a connection to the database server with Jconnect? I'm opening a connection from an application run through a cgi script on the web. It seems that if there is some kind of problem at runtime, the connections are kept open on the server. In the documentation, I haven't found any instruction to do this. Thanks Guibert Englebienne Are you calling _con.close(); You can call this to disconnect. Make sure if you are doing the connect as part of the same try block as the query, you disconnect in a finally block. Here's another thing...

difference between connection.close and command.connection.close
hello, What is the difference between odbcconnection.close and odbccommand.connection.close? I am making connection once in my application in global.asax and opening connection at application_start event and closing it at application_end event. I am accessing connection through "global.myconnection" in webforms. NOw in the webforms,do I have to mycommand.connection.open before comand.executereader?? Does mycommand.connection.close , closes the odbcconnection that I make in gloabl.asax? It is confusing, because on the first function executing on webform, when I myc...

When should I close the database connection
It is said I should close the db connection as soon as possible, but i want to learn the details! thanksWork hard! Play hard! I do not know what details you are looking for. You open late and close early so that the connection can be returned to the connection pool and used by another request.Starting with ASP.NET 2.0? Look at:Programming Microsoft Web Forms My Blog...

Web resources about - Database connection is not closed - asp.net.object-datasource

Connection - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

iMedia Connection: Interactive Marketing News, Features, Podcasts and Video - iMediaConnection.com
If you send more email, you might make more money. Then again, you might destroy your reputation and revenue stream. Here's how to know what ...

HTTP persistent connection - Wikipedia, the free encyclopedia
... tacked on to an existing protocol. If the browser supports keep-alive, it adds an additional header to the request: Following this, the connection ...

MOTHER’S DAY: Facebook Examines Connections Between Moms, Kids
With Mother’s Day on the calendar this coming Sunday, Facebook examined the relationships between mothers and their children on the social network, ...

Police tear open roof to arrest man in connection with stabbing murder
Police have torn open the roof of a Gold Coast home to arrest a man in connection with the stabbing death of 16-year-old Michael Brack.

Paris attacks: Belgium connection probed as terrorist past of Brussels district of Molenbeek under spotlight ...
Prosecutors reveal a growing Belgian connection to the deadly Paris attacks, focusing on a poor Brussels district.

Half of data connections by top 500 Android apps are 'covert' with no effect on user experience
Researchers at the Massachusetts Institute of Technology have discovered that half of the communications connections established by the top free ...

Don’t Let Great Content Fall on Deaf Ears: Know your Connection Strategy
... via employee newsletter when it should have come through small-group manager meetings All of these and more are the result of a faulty connection ...

Brussels Connection Under Spotlight After Paris Killings
(EurActiv) — Prosecutors on Sunday disclosed a growing Belgian connection to the Paris attacks as Premier Charles Michel conceded that a Brussels ...

Be Goofy, Smile At Your Baby: Protection Begins with Connection, Pediatrician Says
VideoPart 3 of a series Andrew Garner wears silly ties and finds it easy to make a goofy face. These are valuable tools for charming the babies ...

Resources last updated: 11/22/2015 2:24:40 AM