I'd like to put the clean up houskeeping items in a finally block at the end
of sub. Specificly i want to close my db connection, however, in the
connection seems to be out of scope in the finally block. Is there a way
aound this?
Code:
Try
Dim conCal As SqlConnection
Dim cmdCal As SqlCommand
Dim dtrCal As SqlDataReader
Dim strDte, endDte As Date
' set the start date to the first date in the month and then set
it to the first date on the calendar grid
strDte = DateAdd("d", -cDte.Day + 1, cDte.Date)
strDte = DateAdd("d", (-strDte.DayOfWeek), strDte.Date)
endDte = DateAdd("d", 35, strDte)
conCal = New SqlConnection("user id=thepronetworke;data
source=""65.36.160.153"";persist security info=True;ini" & _
"tial catalog=ProNetWrkr;password=vf26nu87")
conCal.Open()
cmdCal = New SqlCommand("select calId, calDaate, calShortDesc,
calDesc, CalHoliday from cal where " & _
"calDate >= @strDte and calDate <= @endDte", conCal)
cmdCal.Parameters.Add("@strDte", strDte)
cmdCal.Parameters.Add("@endDte", endDte)
dtrCal = cmdCal.ExecuteReader()
Response.Write(strDte)
Response.Write(endDte)
While dtrCal.Read()
Response.Write(dtrCal("calDate") & " <br>")
End While
dtrCal.Close()
Catch ex As Exception
Dim msg As String = String.Format("msg: {0} <br>Stack Trace:
{1}", _
ex.Message, ex.StackTrace)
lblMsg.Text = ex.GetType.ToString + "<br>" + msg
Finally
conCal.Close()
conCal.Dispose()
End Try
I have a book that saysthis can be done, but this will not compile.
thanks
kes

Signature
I figure if you can''t ask a question honestly, even if it suggests
blasphemy and disturbs the sensibilities of the grand masters of programming
you should quite and join a cult. kes
Steve C. Orr [MVP, MCSD] - 15 Jul 2005 20:40 GMT
Move your connection declaration (Dim conCal...) BEFORE the try statement.
That should do the trick.

Signature
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
> I'd like to put the clean up houskeeping items in a finally block at the
> end
[quoted text clipped - 46 lines]
> thanks
> kes
WebBuilder451 - 15 Jul 2005 20:54 GMT
great!! I knew it had to be simple !!!
thanks you
kes

Signature
I figure if you can''t ask a question honestly, even if it suggests
blasphemy and disturbs the sensibilities of the grand masters of programming
you should quite and join a cult. kes
> Move your connection declaration (Dim conCal...) BEFORE the try statement.
> That should do the trick.
[quoted text clipped - 49 lines]
> > thanks
> > kes