473,725 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trap "connection pool" errors

We have implemented unhandled error trapping at the application level and
log these errors to our database. One error, however, the does not get
trapped is when the connection pool has exceeded the max number of
connections.

Obviously, we need to find the place(s) in our code where connections are
not closed correctly (espcially in loops), but I'm wondering if it's
possible to trap this error and to find out which part of our code (i.e.
stack trace) caused it. It seems logical that the application itself does
not produce the error since there is no error in the codebehind file. Is it
more of an IIS-level error?

Thanks in advance for your thoughts.

Sean
Nov 17 '05 #1
1 3222

"Sean Nolan" <sn****@harrito n.com> wrote in message
news:Oa******** ******@tk2msftn gp13.phx.gbl...
We have implemented unhandled error trapping at the application level and
log these errors to our database. One error, however, the does not get
trapped is when the connection pool has exceeded the max number of
connections.

Obviously, we need to find the place(s) in our code where connections are
not closed correctly (espcially in loops), but I'm wondering if it's
possible to trap this error and to find out which part of our code (i.e.
stack trace) caused it.


It it possible. The general idea is to have a object that will be Garbage
Collected in the same pass as your connection. Whenever a connection is
opened, store the stack trace of the opening method. And put a finalizer on
that object, and write out a trace entry if the finalizer runs and the
connection is still open.

One way to do this is to have a "wrapper object" for your connection.
But then your app code has to create the wrapper instead of the connection.
I think this is a good thing, since you can implement all the DAAB methods
as instance methods of your wrapper object. But that's another story.

Assuming you are using SQLServer (or some other connection that has a
StateChanged event), there may be an easier way.

Without a wrapper object, to get an object which will be finalized at the
same time as the connection we can use a "spy" object.

If we have a "spy" object which handles the StateChaned event of the
SQLConnection, and we give the spy object a reference to the connection we
will have what we want. If 2 objects mutually refer to each other, then
they will always be GC'd at the same time. The spy refers to the
SQLConnection and since the spy handles an event on teh SQLConnection, the
SQLConnection's delegate list contains a reference to the spy object. Voila!

There follows sample program to do this.

David

Imports System.Data.Sql Client

Class ConnectionFacto ry
Private Class ConnectionSpy
Private con As SqlConnection
Dim st As StackTrace
Public Sub New(ByVal con As SqlConnection, ByVal st As StackTrace)
Me.st = st

'latch on to the connection
Me.con = con
AddHandler con.StateChange , AddressOf StateChange
End Sub
Public Sub StateChange(ByV al sender As Object, ByVal args As
System.Data.Sta teChangeEventAr gs)
If args.CurrentSta te = ConnectionState .Closed Then
'detach the spy object and let it float away into space
GC.SuppressFina lize(Me)
RemoveHandler con.StateChange , AddressOf StateChange
con = Nothing
st = Nothing
End If
End Sub
Protected Overrides Sub Finalize()
'if we got here then the connection was not closed.
Trace.WriteLine ("WARNING: Open SQLConnection is being Garbage
Collected")
Trace.WriteLine ("The connection was initially opened " & st.ToString)
End Sub
End Class

Public Shared Function OpenConnection( ByVal connect As String) As
SqlConnection
Dim con As New SqlConnection(c onnect)
con.Open()
Dim st As New StackTrace(True )
Dim sl As New ConnectionSpy(c on, st)

Return con
End Function

End Class
Module Module1

Sub Main()
'pipe trace output to the console
'in your app this would go to a trace file
System.Diagnost ics.Trace.Liste ners.Add(New
TextWriterTrace Listener(System .Console.Out))
Dim connect As String = "..."
Dim c As SqlConnection = ConnectionFacto ry.OpenConnecti on(connect)
c = Nothing '!!the connection was not closed

c = ConnectionFacto ry.OpenConnecti on(connect)
c.Close() 'this time it was closed
c = Nothing

GC.Collect(GC.M axGeneration)
GC.WaitForPendi ngFinalizers()
'output will show 1 warning
End Sub

End Module

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2708
by: Leif Wessman | last post by:
I have a php-webpage that needs the database in the beginning and in the end of the script. In the middle there is a lot of processing that takes several seconds - during that time I don't use the database connection. What is the best approach? Should I close the connection after I'm done with it OR should I reuse the connection thru my whole script? Where can I read more about this? Any pointers?
0
2697
by: Henry | last post by:
Hi, I have cases where I connect to the web site and MySQL is not working : Message : "Too many connection errors", Unblock with 'mysqladmin flush-hosts'. What I did is a script that check out /etc/init.d/mysqld status and if is not running, then, I restart MySQL.
0
1309
by: Bill | last post by:
Attempting to register (from a Win XP Pro machine) to my SQL Server 2000 machine (Win 2K Server), via Internet (http), error says "Errors occurred while connecting to 'mysqlserver'. Cannot open connection to Analysis server 'mysqlserver'. Network error 'mysqlserver' Do you still want to register this server?" Query Analyzer and Enterprise Manager connected right up the first time, and have worked AOK ever since.
1
4193
by: Muscha | last post by:
Hello, Every now and then my application throw this exception: "Unable to read data from the transport connection" And when I break into the Visual Studio, the thread where it failed has none of my code and the following is the call stack:
0
261
by: Philip Townsend | last post by:
I have a asp.net application that is periodically generating an error stating that the maximum number of connections has been exceeded. Is there a way to trap this error and reset the connection pool when the error occurs? Any other suggestions? Thanks...! *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
0
18459
by: BGS | last post by:
I have a web site (www.on-the-matrix.com) that displays photos in a "slide show" format on ASPX pages that run in an inline frame on an ASP page (or in a separate pop-up window). The ASPX pages use a hidden form to transmit information back to the server so it will know which is the next photo to load. All of this works as intended in modern versions of Internet Explorer, Netscape and Mozilla. With Opera, however, users receive a...
6
4495
by: karim | last post by:
I have an asp.net page that stopped running properly giving the error below. The app uses a SQL Server 2000 on another server. Enterprise Manager and Query analyzer on the web server can connect to that sql server just fine and run queries. I rebooted the web server and made aspnet member of the admin group. I don't know why the error mentions open connections if I can open several query anaylzer windows using the same sql server...
7
11249
by: Henry | last post by:
I am writing a Windows forms VB.Net/MS SQL application via VS 2003 that utilizes Crystal Reports. I want to be able to dynamically set the report data source at run time. I'm trying to change the the reports "integrated security" from TRUE to FALSE via the "Set Location" dialog in the report designer with no success. It is not intuitive (at least not to me.) I get the following error:
2
4912
by: one | last post by:
Hi, Was wondering if you could help me out with regards to a server that I'm trying to troubleshoot... Basically we have a windows 2003 load-balanced server that has got sharepoint and mcms installed. The other day, I was about to change the access settings for a specific virtual folder for MCMS, when I noticed that the Application Pool for
0
8872
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8747
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9246
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9162
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9091
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6694
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3211
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2619
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.