Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / July 2005

Tip: Looking for answers? Try searching our database.

try and finally question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WebBuilder451 - 15 Jul 2005 20:37 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.