G
Guest
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
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