473,320 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Try...Catch...Finally not firing finally?

Howdy,

I ran into a very interesting issue and I'm curios as to how this is suppose
to work. I am using Try...Catch...Finally statements for all database
connectivity in my ASP.NET 2.0 web application. I'm connecting to IBM's
Universe 10.2 using UniObjects.Net. Anyway, if the connection errors, the
Finally closes the connection. What I see happening is that the function in
the Finally statement either isn't running or doesn't apply what its suppose
to.

For example. Running Visual Studio 2005, I debug my web app and step through
a function that I am purposly erroring on. The session opens, then a command
errors out. In the Catch I am taking the ex.tostring and sending it to a
class function that I then email that to myself and then send the user to a
default error page using server.transfer("page",false). After that function
runs, the debugger sends me back to the calling function, finishes the Catch
then fires the Finally, which closes the session.

So my problem is that it appears that the database session is not closing in
the finally. I just moved the close session to the first line in the Catch
and it appears to close it properly...

Thanks!!

David Lozzi

Apr 23 '07 #1
12 2633

What exactly does the finally clause look like? Is it possible that
something within the finally clause is generating a second error
before the database "session" is closed (what do you mean exactly,
connection? if so use the using clause instead anyways).

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Mon, 23 Apr 2007 17:46:36 -0400, "David Lozzi"
<dl****@nospam.nospamwrote:
>Howdy,

I ran into a very interesting issue and I'm curios as to how this is suppose
to work. I am using Try...Catch...Finally statements for all database
connectivity in my ASP.NET 2.0 web application. I'm connecting to IBM's
Universe 10.2 using UniObjects.Net. Anyway, if the connection errors, the
Finally closes the connection. What I see happening is that the function in
the Finally statement either isn't running or doesn't apply what its suppose
to.

For example. Running Visual Studio 2005, I debug my web app and step through
a function that I am purposly erroring on. The session opens, then a command
errors out. In the Catch I am taking the ex.tostring and sending it to a
class function that I then email that to myself and then send the user to a
default error page using server.transfer("page",false). After that function
runs, the debugger sends me back to the calling function, finishes the Catch
then fires the Finally, which closes the session.

So my problem is that it appears that the database session is not closing in
the finally. I just moved the close session to the first line in the Catch
and it appears to close it properly...

Thanks!!

David Lozzi
Apr 24 '07 #2
server transfer aborts the current thread, so the finally will not fire.
you should not call it in a catch statement.

-- bruce (sqlwork.com)

David Lozzi wrote:
Howdy,

I ran into a very interesting issue and I'm curios as to how this is
suppose to work. I am using Try...Catch...Finally statements for all
database connectivity in my ASP.NET 2.0 web application. I'm connecting
to IBM's Universe 10.2 using UniObjects.Net. Anyway, if the connection
errors, the Finally closes the connection. What I see happening is that
the function in the Finally statement either isn't running or doesn't
apply what its suppose to.

For example. Running Visual Studio 2005, I debug my web app and step
through a function that I am purposly erroring on. The session opens,
then a command errors out. In the Catch I am taking the ex.tostring and
sending it to a class function that I then email that to myself and then
send the user to a default error page using
server.transfer("page",false). After that function runs, the debugger
sends me back to the calling function, finishes the Catch then fires the
Finally, which closes the session.

So my problem is that it appears that the database session is not
closing in the finally. I just moved the close session to the first line
in the Catch and it appears to close it properly...

Thanks!!

David Lozzi
Apr 24 '07 #3

Not true. The finally always runs.

protected void Page_Load(object sender, EventArgs e)
{
try
{
Log.Debug(this, "Throwing error...");
throw new Exception();
}
catch
{
Log.Debug(this, "Caught..");
Server.Transfer("gateway.aspx", false);
}
finally
{
Log.Debug(this, "Finally...");
}
}
produced..

2007-04-24 12:22:46.98 [2276] DEBUG ASP.default_aspx - Throwing
error...
2007-04-24 12:22:46.98 [2276] DEBUG ASP.default_aspx - Caught..
2007-04-24 12:22:46.98 [2276] DEBUG ASP.default_aspx - Finally...

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Tue, 24 Apr 2007 08:49:33 -0700, bruce barker <no****@nospam.com>
wrote:
>server transfer aborts the current thread, so the finally will not fire.
you should not call it in a catch statement.

-- bruce (sqlwork.com)
Apr 24 '07 #4
The two conditions really aren't related - i don't think. Finally blocks
always fire, there's an implicit guarantee for that. True there was a bug in
1.1 that abrogated that guarantee, but it is fixed in 2.0. So the problem
would lie in the close code. It's quite possible that close is erroring out.
Put a trace from the db end to see if the close command is funneling thru to
the database engine.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"David Lozzi" <dl****@nospam.nospamwrote in message
news:C8**********************************@microsof t.com...
Howdy,

I ran into a very interesting issue and I'm curios as to how this is
suppose to work. I am using Try...Catch...Finally statements for all
database connectivity in my ASP.NET 2.0 web application. I'm connecting to
IBM's Universe 10.2 using UniObjects.Net. Anyway, if the connection
errors, the Finally closes the connection. What I see happening is that
the function in the Finally statement either isn't running or doesn't
apply what its suppose to.

For example. Running Visual Studio 2005, I debug my web app and step
through a function that I am purposly erroring on. The session opens, then
a command errors out. In the Catch I am taking the ex.tostring and sending
it to a class function that I then email that to myself and then send the
user to a default error page using server.transfer("page",false). After
that function runs, the debugger sends me back to the calling function,
finishes the Catch then fires the Finally, which closes the session.

So my problem is that it appears that the database session is not closing
in the finally. I just moved the close session to the first line in the
Catch and it appears to close it properly...

Thanks!!

David Lozzi

Apr 25 '07 #5
I ran a similar test instead used response.write() and it never reached the
finally........

"Samuel R. Neff" <sa********@nomail.comwrote in message
news:dh********************************@4ax.com...
>
Not true. The finally always runs.

protected void Page_Load(object sender, EventArgs e)
{
try
{
Log.Debug(this, "Throwing error...");
throw new Exception();
}
catch
{
Log.Debug(this, "Caught..");
Server.Transfer("gateway.aspx", false);
}
finally
{
Log.Debug(this, "Finally...");
}
}
produced..

2007-04-24 12:22:46.98 [2276] DEBUG ASP.default_aspx - Throwing
error...
2007-04-24 12:22:46.98 [2276] DEBUG ASP.default_aspx - Caught..
2007-04-24 12:22:46.98 [2276] DEBUG ASP.default_aspx - Finally...

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Tue, 24 Apr 2007 08:49:33 -0700, bruce barker <no****@nospam.com>
wrote:
>>server transfer aborts the current thread, so the finally will not fire.
you should not call it in a catch statement.

-- bruce (sqlwork.com)
May 7 '07 #6
I ran a test using response.write() in each section of the try, and it never
reached the finally........

And the close works fine, it calls a simple
UniObjects.CloseSession(unisession). And when I moved it to the first line
of the catch it works fine everytime. We had a trace running on the DB end
and it kept saying that the session was never closed, no other errors.
"Alvin Bruney [MVP]" <some guy without an email addresswrote in message
news:O0**************@TK2MSFTNGP03.phx.gbl...
The two conditions really aren't related - i don't think. Finally blocks
always fire, there's an implicit guarantee for that. True there was a bug
in 1.1 that abrogated that guarantee, but it is fixed in 2.0. So the
problem would lie in the close code. It's quite possible that close is
erroring out. Put a trace from the db end to see if the close command is
funneling thru to the database engine.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"David Lozzi" <dl****@nospam.nospamwrote in message
news:C8**********************************@microsof t.com...
>Howdy,

I ran into a very interesting issue and I'm curios as to how this is
suppose to work. I am using Try...Catch...Finally statements for all
database connectivity in my ASP.NET 2.0 web application. I'm connecting
to IBM's Universe 10.2 using UniObjects.Net. Anyway, if the connection
errors, the Finally closes the connection. What I see happening is that
the function in the Finally statement either isn't running or doesn't
apply what its suppose to.

For example. Running Visual Studio 2005, I debug my web app and step
through a function that I am purposly erroring on. The session opens,
then a command errors out. In the Catch I am taking the ex.tostring and
sending it to a class function that I then email that to myself and then
send the user to a default error page using
server.transfer("page",false). After that function runs, the debugger
sends me back to the calling function, finishes the Catch then fires the
Finally, which closes the session.

So my problem is that it appears that the database session is not closing
in the finally. I just moved the close session to the first line in the
Catch and it appears to close it properly...

Thanks!!

David Lozzi

May 7 '07 #7
Can you post a short sample application that demonstrates the problem, i'd
like to take a closer look.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"David Lozzi" <dl****@nospam.nospamwrote in message
news:C3**********************************@microsof t.com...
>I ran a test using response.write() in each section of the try, and it
never reached the finally........

And the close works fine, it calls a simple
UniObjects.CloseSession(unisession). And when I moved it to the first line
of the catch it works fine everytime. We had a trace running on the DB end
and it kept saying that the session was never closed, no other errors.
"Alvin Bruney [MVP]" <some guy without an email addresswrote in message
news:O0**************@TK2MSFTNGP03.phx.gbl...
>The two conditions really aren't related - i don't think. Finally blocks
always fire, there's an implicit guarantee for that. True there was a bug
in 1.1 that abrogated that guarantee, but it is fixed in 2.0. So the
problem would lie in the close code. It's quite possible that close is
erroring out. Put a trace from the db end to see if the close command is
funneling thru to the database engine.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"David Lozzi" <dl****@nospam.nospamwrote in message
news:C8**********************************@microso ft.com...
>>Howdy,

I ran into a very interesting issue and I'm curios as to how this is
suppose to work. I am using Try...Catch...Finally statements for all
database connectivity in my ASP.NET 2.0 web application. I'm connecting
to IBM's Universe 10.2 using UniObjects.Net. Anyway, if the connection
errors, the Finally closes the connection. What I see happening is that
the function in the Finally statement either isn't running or doesn't
apply what its suppose to.

For example. Running Visual Studio 2005, I debug my web app and step
through a function that I am purposly erroring on. The session opens,
then a command errors out. In the Catch I am taking the ex.tostring and
sending it to a class function that I then email that to myself and then
send the user to a default error page using
server.transfer("page",false). After that function runs, the debugger
sends me back to the calling function, finishes the Catch then fires the
Finally, which closes the session.

So my problem is that it appears that the database session is not
closing in the finally. I just moved the close session to the first line
in the Catch and it appears to close it properly...

Thanks!!

David Lozzi


May 7 '07 #8
Sure, below. This is how it was, now the UOCloseSession function is before
the EmailError function.

Thanks!!
Public Function GetProduct(ByVal strPartNo As String) As Boolean
Dim uniSession As UniSession = Nothing

Try
uniSession = UOOpenSession()

Dim unicom As UniCommand = uniSession.CreateUniCommand
Dim subtext As String = ""
Dim qry As String = "LIST PARTS.WEB WITH @ID = " & strPartNo & "
DESC IMAGE DL.NOTES DISC_FLG GIFT_WRAP SIZEFLAG1 EXPECTED.DATE PRICE
MEDLEY_PARTS MEDLEY_IMAGES MEDLEY_STYLE PERSINSTR RELPARTS1 RELDESC1
PROD.TYPE TOXML ELEMENTS"
unicom.Command = qry
unicom.Execute()
subtext = Mid(unicom.Response, InStr(unicom.Response, "<"),
Len(unicom.Response))
unicom.Dispose()

........ stuff .......
Catch ex As Exception
EmailError("product_details.vb", "GetProduct", ex.ToString,
"Partno=" & strPartNo)
Return False
Finally
UOCloseSession(uniSession)
End Try
Public Shared Function UOCloseSession(ByRef unisess As UniSession)
UniObjects.CloseSession(unisess)
End Function
Public Shared Function EmailError(ByVal strPage As String, ByVal
strFunction As String, ByVal strError As String, Optional ByVal strOther As
String = "", Optional ByVal bolSend As Boolean = True, Optional ByVal
intLogType As Integer = 1)
If ConfigurationManager.AppSettings("ErrorEmailNotifi cations") =
True Then
If Not strError.Contains("viewstate MAC") Then
Dim msg As New MailMessage

msg.From = New
MailAddress(ConfigurationManager.AppSettings("Erro rEmailFrom"))

Dim toEmails() As String =
ConfigurationManager.AppSettings("ErrorEmailTo").S plit(";")
For i As Integer = 0 To toEmails.Length - 1
msg.To.Add(toEmails(i))
Next

msg.Subject = "Error on " &
Current.Request.ServerVariables("SERVER_NAME") & " Website"
msg.IsBodyHtml = True
msg.Body = "<font face=verdana size='2'><b>Error on " &
Current.Request.ServerVariables("SERVER_NAME") & " Website!</b><br>" & Now()
& "<BR><br>" & _
"<b>Page Name:</b" & strPage & "<br>" & _
"<b>URL:</b>" &
Current.Request.ServerVariables("URL") & "<br>" & _
"<b>Function Name:</b" & strFunction & "<br><br>"
& _
"<b>Error Message:</b" & strError & "<br><br>"

Dim smtpClient As New SmtpClient
smtpClient.Host = ConfigurationManager.AppSettings("SMTPServer")
smtpClient.Send(msg)
Current.Application("ErrorEmail") = Nothing
End If
Else
If Current.Application("ErrorEmail") Is Nothing Then
Dim msg As New MailMessage

msg.From = New
MailAddress(ConfigurationManager.AppSettings("Erro rEmailFrom"))

Dim toEmails() As String =
ConfigurationManager.AppSettings("ErrorEmailTo").S plit(";")
For i As Integer = 0 To toEmails.Length - 1
msg.To.Add(toEmails(i))
Next

msg.Subject = "Errors are disabled on " & WebsiteName & "
Website"
msg.IsBodyHtml = True
msg.Body = "<font face=verdana size='2'><b>Error
notification is disabled on " & WebsiteName & " however an error occured!"

Dim smtpClient As New SmtpClient
smtpClient.Host =
ConfigurationManager.AppSettings("SMTPServer")
smtpClient.Send(msg)
Current.Application("ErrorEmail") = "done"
End If
End If

If bolSend Then
Current.Server.Transfer("~/oops.aspx", False)
End If

Return True
End Function
"Alvin Bruney [MVP]" <some guy without an email addresswrote in message
news:eK**************@TK2MSFTNGP05.phx.gbl...
Can you post a short sample application that demonstrates the problem, i'd
like to take a closer look.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"David Lozzi" <dl****@nospam.nospamwrote in message
news:C3**********************************@microsof t.com...
>>I ran a test using response.write() in each section of the try, and it
never reached the finally........

And the close works fine, it calls a simple
UniObjects.CloseSession(unisession). And when I moved it to the first
line of the catch it works fine everytime. We had a trace running on the
DB end and it kept saying that the session was never closed, no other
errors.
"Alvin Bruney [MVP]" <some guy without an email addresswrote in message
news:O0**************@TK2MSFTNGP03.phx.gbl...
>>The two conditions really aren't related - i don't think. Finally blocks
always fire, there's an implicit guarantee for that. True there was a
bug in 1.1 that abrogated that guarantee, but it is fixed in 2.0. So the
problem would lie in the close code. It's quite possible that close is
erroring out. Put a trace from the db end to see if the close command is
funneling thru to the database engine.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"David Lozzi" <dl****@nospam.nospamwrote in message
news:C8**********************************@micros oft.com...
Howdy,

I ran into a very interesting issue and I'm curios as to how this is
suppose to work. I am using Try...Catch...Finally statements for all
database connectivity in my ASP.NET 2.0 web application. I'm connecting
to IBM's Universe 10.2 using UniObjects.Net. Anyway, if the connection
errors, the Finally closes the connection. What I see happening is that
the function in the Finally statement either isn't running or doesn't
apply what its suppose to.

For example. Running Visual Studio 2005, I debug my web app and step
through a function that I am purposly erroring on. The session opens,
then a command errors out. In the Catch I am taking the ex.tostring and
sending it to a class function that I then email that to myself and
then send the user to a default error page using
server.transfer("page",false). After that function runs, the debugger
sends me back to the calling function, finishes the Catch then fires
the Finally, which closes the session.

So my problem is that it appears that the database session is not
closing in the finally. I just moved the close session to the first
line in the Catch and it appears to close it properly...

Thanks!!

David Lozzi


May 8 '07 #9

Have to be careful that the test is really testing what you think it
is. Testing with Response.Write() will test not only that the finally
is reached but also that the Response stream is still valid at that
point, which it isn't.

HTH,

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Mon, 7 May 2007 15:55:18 -0400, "David Lozzi"
<dl****@nospam.nospamwrote:
>I ran a similar test instead used response.write() and it never reached the
finally........

"Samuel R. Neff" <sa********@nomail.comwrote in message
news:dh********************************@4ax.com.. .
>>
Not true. The finally always runs.

protected void Page_Load(object sender, EventArgs e)
{
try
{
Log.Debug(this, "Throwing error...");
throw new Exception();
}
catch
{
Log.Debug(this, "Caught..");
Server.Transfer("gateway.aspx", false);
}
finally
{
Log.Debug(this, "Finally...");
}
}
produced..

2007-04-24 12:22:46.98 [2276] DEBUG ASP.default_aspx - Throwing
error...
2007-04-24 12:22:46.98 [2276] DEBUG ASP.default_aspx - Caught..
2007-04-24 12:22:46.98 [2276] DEBUG ASP.default_aspx - Finally...

Sam
May 8 '07 #10
Interesting.... So the Log.Debug, what does that do?
"Samuel R. Neff" <sa********@nomail.comwrote in message
news:nb********************************@4ax.com...
>
Have to be careful that the test is really testing what you think it
is. Testing with Response.Write() will test not only that the finally
is reached but also that the Response stream is still valid at that
point, which it isn't.

HTH,

Sam
------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.
On Mon, 7 May 2007 15:55:18 -0400, "David Lozzi"
<dl****@nospam.nospamwrote:
>>I ran a similar test instead used response.write() and it never reached
the
finally........

"Samuel R. Neff" <sa********@nomail.comwrote in message
news:dh********************************@4ax.com. ..
>>>
Not true. The finally always runs.

protected void Page_Load(object sender, EventArgs e)
{
try
{
Log.Debug(this, "Throwing error...");
throw new Exception();
}
catch
{
Log.Debug(this, "Caught..");
Server.Transfer("gateway.aspx", false);
}
finally
{
Log.Debug(this, "Finally...");
}
}
produced..

2007-04-24 12:22:46.98 [2276] DEBUG ASP.default_aspx - Throwing
error...
2007-04-24 12:22:46.98 [2276] DEBUG ASP.default_aspx - Caught..
2007-04-24 12:22:46.98 [2276] DEBUG ASP.default_aspx - Finally...

Sam
May 10 '07 #11

Log.Debug is simply a static wrapper around log4net which I have
configured to log to a text file.

Sam

------------------------------------------------------------
We're hiring! B-Line Medical is seeking .NET
Developers for exciting positions in medical product
development in MD/DC. Work with a variety of technologies
in a relaxed team environment. See ads on Dice.com.

On Thu, 10 May 2007 09:11:27 -0400, "David Lozzi"
<dl****@nospam.nospamwrote:
>Interesting.... So the Log.Debug, what does that do?
"Samuel R. Neff" <sa********@nomail.comwrote in message
news:nb********************************@4ax.com.. .
>>
Have to be careful that the test is really testing what you think it
is. Testing with Response.Write() will test not only that the finally
is reached but also that the Response stream is still valid at that
point, which it isn't.

HTH,

Sam

May 10 '07 #12
Finally blocks going off like clock work on my end. I had to convert your vb
in c# and stub some methods. I simply threw an exception in the constructor
of the unisession object to duplicate your issue.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"David Lozzi" <dl****@nospam.nospamwrote in message
news:F8**********************************@microsof t.com...
Sure, below. This is how it was, now the UOCloseSession function is before
the EmailError function.

Thanks!!
Public Function GetProduct(ByVal strPartNo As String) As Boolean
Dim uniSession As UniSession = Nothing

Try
uniSession = UOOpenSession()

Dim unicom As UniCommand = uniSession.CreateUniCommand
Dim subtext As String = ""
Dim qry As String = "LIST PARTS.WEB WITH @ID = " & strPartNo &
" DESC IMAGE DL.NOTES DISC_FLG GIFT_WRAP SIZEFLAG1 EXPECTED.DATE PRICE
MEDLEY_PARTS MEDLEY_IMAGES MEDLEY_STYLE PERSINSTR RELPARTS1 RELDESC1
PROD.TYPE TOXML ELEMENTS"
unicom.Command = qry
unicom.Execute()
subtext = Mid(unicom.Response, InStr(unicom.Response, "<"),
Len(unicom.Response))
unicom.Dispose()

........ stuff .......
Catch ex As Exception
EmailError("product_details.vb", "GetProduct", ex.ToString,
"Partno=" & strPartNo)
Return False
Finally
UOCloseSession(uniSession)
End Try
Public Shared Function UOCloseSession(ByRef unisess As UniSession)
UniObjects.CloseSession(unisess)
End Function
Public Shared Function EmailError(ByVal strPage As String, ByVal
strFunction As String, ByVal strError As String, Optional ByVal strOther
As String = "", Optional ByVal bolSend As Boolean = True, Optional ByVal
intLogType As Integer = 1)
If ConfigurationManager.AppSettings("ErrorEmailNotifi cations") =
True Then
If Not strError.Contains("viewstate MAC") Then
Dim msg As New MailMessage

msg.From = New
MailAddress(ConfigurationManager.AppSettings("Erro rEmailFrom"))

Dim toEmails() As String =
ConfigurationManager.AppSettings("ErrorEmailTo").S plit(";")
For i As Integer = 0 To toEmails.Length - 1
msg.To.Add(toEmails(i))
Next

msg.Subject = "Error on " &
Current.Request.ServerVariables("SERVER_NAME") & " Website"
msg.IsBodyHtml = True
msg.Body = "<font face=verdana size='2'><b>Error on " &
Current.Request.ServerVariables("SERVER_NAME") & " Website!</b><br>" &
Now() & "<BR><br>" & _
"<b>Page Name:</b" & strPage & "<br>" & _
"<b>URL:</b>" &
Current.Request.ServerVariables("URL") & "<br>" & _
"<b>Function Name:</b" & strFunction & "<br><br>"
& _
"<b>Error Message:</b" & strError & "<br><br>"

Dim smtpClient As New SmtpClient
smtpClient.Host =
ConfigurationManager.AppSettings("SMTPServer")
smtpClient.Send(msg)
Current.Application("ErrorEmail") = Nothing
End If
Else
If Current.Application("ErrorEmail") Is Nothing Then
Dim msg As New MailMessage

msg.From = New
MailAddress(ConfigurationManager.AppSettings("Erro rEmailFrom"))

Dim toEmails() As String =
ConfigurationManager.AppSettings("ErrorEmailTo").S plit(";")
For i As Integer = 0 To toEmails.Length - 1
msg.To.Add(toEmails(i))
Next

msg.Subject = "Errors are disabled on " & WebsiteName & "
Website"
msg.IsBodyHtml = True
msg.Body = "<font face=verdana size='2'><b>Error
notification is disabled on " & WebsiteName & " however an error occured!"

Dim smtpClient As New SmtpClient
smtpClient.Host =
ConfigurationManager.AppSettings("SMTPServer")
smtpClient.Send(msg)
Current.Application("ErrorEmail") = "done"
End If
End If

If bolSend Then
Current.Server.Transfer("~/oops.aspx", False)
End If

Return True
End Function
"Alvin Bruney [MVP]" <some guy without an email addresswrote in message
news:eK**************@TK2MSFTNGP05.phx.gbl...
>Can you post a short sample application that demonstrates the problem,
i'd like to take a closer look.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"David Lozzi" <dl****@nospam.nospamwrote in message
news:C3**********************************@microso ft.com...
>>>I ran a test using response.write() in each section of the try, and it
never reached the finally........

And the close works fine, it calls a simple
UniObjects.CloseSession(unisession). And when I moved it to the first
line of the catch it works fine everytime. We had a trace running on the
DB end and it kept saying that the session was never closed, no other
errors.
"Alvin Bruney [MVP]" <some guy without an email addresswrote in
message news:O0**************@TK2MSFTNGP03.phx.gbl...
The two conditions really aren't related - i don't think. Finally
blocks always fire, there's an implicit guarantee for that. True there
was a bug in 1.1 that abrogated that guarantee, but it is fixed in 2.0.
So the problem would lie in the close code. It's quite possible that
close is erroring out. Put a trace from the db end to see if the close
command is funneling thru to the database engine.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley
"David Lozzi" <dl****@nospam.nospamwrote in message
news:C8**********************************@micro soft.com...
Howdy,
>
I ran into a very interesting issue and I'm curios as to how this is
suppose to work. I am using Try...Catch...Finally statements for all
database connectivity in my ASP.NET 2.0 web application. I'm
connecting to IBM's Universe 10.2 using UniObjects.Net. Anyway, if the
connection errors, the Finally closes the connection. What I see
happening is that the function in the Finally statement either isn't
running or doesn't apply what its suppose to.
>
For example. Running Visual Studio 2005, I debug my web app and step
through a function that I am purposly erroring on. The session opens,
then a command errors out. In the Catch I am taking the ex.tostring
and sending it to a class function that I then email that to myself
and then send the user to a default error page using
server.transfer("page",false). After that function runs, the debugger
sends me back to the calling function, finishes the Catch then fires
the Finally, which closes the session.
>
So my problem is that it appears that the database session is not
closing in the finally. I just moved the close session to the first
line in the Catch and it appears to close it properly...
>
Thanks!!
>
David Lozzi


May 11 '07 #13

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

Similar topics

8
by: Z D | last post by:
Hi, I was wondering what's the point of "finally" is in a try..catch..finally block? Isn't it the same to put the code that would be in the "finally" section right after the try/catch block?...
11
by: Pohihihi | last post by:
I was wondering what is the ill effect of using try catch in the code, both nested and simple big one. e.g. try { \\ whole app code goes here } catch (Exception ee) {}
23
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
13
by: Woody Splawn | last post by:
I have a try catch statement in a fucntion that is supposed to return a true or a false My code looks like this: Try mySqlConnection.Open() Dim Da1 As New SqlDataAdapter("Select JnlType,...
7
by: Sean Kirkpatrick | last post by:
I got caught with my pants down the other day when trying to explain Try...Catch...Finally and things didn't work as I had assumed. Perhaps someone can explain to me the purpose of Finally. I've...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
6
by: foolmelon | last post by:
If a childThread is in the middle of a catch block and handling an exception caught, the main thread calls childThread.Abort(). At that time a ThreadAbortException is thrown in the childThread. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.