Hi,
I know this has been discussed before and I have read the earlier posts but
I am still unclear.
I have code that was written in 1.1

Dim cmdConn As SqlClient.SqlCommand

Dim cmdSource As SqlClient.SqlDataReader

Dim other stuff

try

Instantiate the objects and do the business

Catch

logging error etc

Finally

cmdSource.Close()

cmdConn.Dispose()

End Try

Now in CLR 2.0 I am warned that the finally block is using unassigned
variables. (Which it is)

I am tempted to ditch the finally clause and leave it to the Garbage
collector.

What is the recommended code structure in this situation.

Thanks

Bob

Re: CLR 2.0, SQl objects and dispose by Maarten

Maarten
Mon Mar 27 10:18:04 CST 2006

Place the declarations in the Try.

"Bob" <bob@nowhere.com> wrote in message
news:OgehySTUGHA.3888@TK2MSFTNGP10.phx.gbl...
> Hi,
> I know this has been discussed before and I have read the earlier posts
> but
> I am still unclear.
> I have code that was written in 1.1
>
> Dim cmdConn As SqlClient.SqlCommand
>
> Dim cmdSource As SqlClient.SqlDataReader
>
> Dim other stuff
>
> try
>
> Instantiate the objects and do the business
>
> Catch
>
> logging error etc
>
> Finally
>
> cmdSource.Close()
>
> cmdConn.Dispose()
>
> End Try
>
> Now in CLR 2.0 I am warned that the finally block is using unassigned
> variables. (Which it is)
>
> I am tempted to ditch the finally clause and leave it to the Garbage
> collector.
>
> What is the recommended code structure in this situation.
>
> Thanks
>
> Bob
>
>



Re: CLR 2.0, SQl objects and dispose by Bob

Bob
Mon Mar 27 21:34:13 CST 2006

Hi Maarten,
No, this doesn't work. The warning goes from unitialised to Error
undeclared variables.
regards
Bob
"Maarten" <NoSpam@me.com> wrote in message
news:%23mqmeobUGHA.4764@TK2MSFTNGP11.phx.gbl...
> Place the declarations in the Try.
>
> "Bob" <bob@nowhere.com> wrote in message
> news:OgehySTUGHA.3888@TK2MSFTNGP10.phx.gbl...
> > Hi,
> > I know this has been discussed before and I have read the earlier posts
> > but
> > I am still unclear.
> > I have code that was written in 1.1
> >
> > Dim cmdConn As SqlClient.SqlCommand
> >
> > Dim cmdSource As SqlClient.SqlDataReader
> >
> > Dim other stuff
> >
> > try
> >
> > Instantiate the objects and do the business
> >
> > Catch
> >
> > logging error etc
> >
> > Finally
> >
> > cmdSource.Close()
> >
> > cmdConn.Dispose()
> >
> > End Try
> >
> > Now in CLR 2.0 I am warned that the finally block is using unassigned
> > variables. (Which it is)
> >
> > I am tempted to ditch the finally clause and leave it to the Garbage
> > collector.
> >
> > What is the recommended code structure in this situation.
> >
> > Thanks
> >
> > Bob
> >
> >
>
>



Re: CLR 2.0, SQl objects and dispose by Bob

Bob
Mon Mar 27 21:42:04 CST 2006

Further to my last post, I am going to put the disposes inside the try
block.
If there is an error then I'll leave it to the GC to clean up after the
Catches clause has done its thing.
Unless...
Some one has a better idea.
Thanks
Bob
"Maarten" <NoSpam@me.com> wrote in message
news:%23mqmeobUGHA.4764@TK2MSFTNGP11.phx.gbl...
> Place the declarations in the Try.
>
> "Bob" <bob@nowhere.com> wrote in message
> news:OgehySTUGHA.3888@TK2MSFTNGP10.phx.gbl...
> > Hi,
> > I know this has been discussed before and I have read the earlier posts
> > but
> > I am still unclear.
> > I have code that was written in 1.1
> >
> > Dim cmdConn As SqlClient.SqlCommand
> >
> > Dim cmdSource As SqlClient.SqlDataReader
> >
> > Dim other stuff
> >
> > try
> >
> > Instantiate the objects and do the business
> >
> > Catch
> >
> > logging error etc
> >
> > Finally
> >
> > cmdSource.Close()
> >
> > cmdConn.Dispose()
> >
> > End Try
> >
> > Now in CLR 2.0 I am warned that the finally block is using unassigned
> > variables. (Which it is)
> >
> > I am tempted to ditch the finally clause and leave it to the Garbage
> > collector.
> >
> > What is the recommended code structure in this situation.
> >
> > Thanks
> >
> > Bob
> >
> >
>
>



Re: CLR 2.0, SQl objects and dispose by Maarten

Maarten
Tue Mar 28 01:05:46 CST 2006

try
dim cmdConn as SqlClient.SqlCommand = nothing
Dim cmdSource as SqlClient.SqlDataReader = nothing
etc
etc


"Bob" <bob@nowhere.com> wrote in message
news:eewAykhUGHA.4348@TK2MSFTNGP09.phx.gbl...
> Further to my last post, I am going to put the disposes inside the try
> block.
> If there is an error then I'll leave it to the GC to clean up after the
> Catches clause has done its thing.
> Unless...
> Some one has a better idea.
> Thanks
> Bob
> "Maarten" <NoSpam@me.com> wrote in message
> news:%23mqmeobUGHA.4764@TK2MSFTNGP11.phx.gbl...
>> Place the declarations in the Try.
>>
>> "Bob" <bob@nowhere.com> wrote in message
>> news:OgehySTUGHA.3888@TK2MSFTNGP10.phx.gbl...
>> > Hi,
>> > I know this has been discussed before and I have read the earlier posts
>> > but
>> > I am still unclear.
>> > I have code that was written in 1.1
>> >
>> > Dim cmdConn As SqlClient.SqlCommand
>> >
>> > Dim cmdSource As SqlClient.SqlDataReader
>> >
>> > Dim other stuff
>> >
>> > try
>> >
>> > Instantiate the objects and do the business
>> >
>> > Catch
>> >
>> > logging error etc
>> >
>> > Finally
>> >
>> > cmdSource.Close()
>> >
>> > cmdConn.Dispose()
>> >
>> > End Try
>> >
>> > Now in CLR 2.0 I am warned that the finally block is using unassigned
>> > variables. (Which it is)
>> >
>> > I am tempted to ditch the finally clause and leave it to the Garbage
>> > collector.
>> >
>> > What is the recommended code structure in this situation.
>> >
>> > Thanks
>> >
>> > Bob
>> >
>> >
>>
>>
>
>



Re: CLR 2.0, SQl objects and dispose by Bob

Bob
Tue Mar 28 18:17:21 CST 2006

Hi Maarten,
Jackpot.
thanks
Bob
"Maarten" <NoSpam@me.com> wrote in message
news:%23k8QiYjUGHA.5004@TK2MSFTNGP11.phx.gbl...
> try
> dim cmdConn as SqlClient.SqlCommand = nothing
> Dim cmdSource as SqlClient.SqlDataReader = nothing
> etc
> etc
>
>
> "Bob" <bob@nowhere.com> wrote in message
> news:eewAykhUGHA.4348@TK2MSFTNGP09.phx.gbl...
> > Further to my last post, I am going to put the disposes inside the try
> > block.
> > If there is an error then I'll leave it to the GC to clean up after the
> > Catches clause has done its thing.
> > Unless...
> > Some one has a better idea.
> > Thanks
> > Bob
> > "Maarten" <NoSpam@me.com> wrote in message
> > news:%23mqmeobUGHA.4764@TK2MSFTNGP11.phx.gbl...
> >> Place the declarations in the Try.
> >>
> >> "Bob" <bob@nowhere.com> wrote in message
> >> news:OgehySTUGHA.3888@TK2MSFTNGP10.phx.gbl...
> >> > Hi,
> >> > I know this has been discussed before and I have read the earlier
posts
> >> > but
> >> > I am still unclear.
> >> > I have code that was written in 1.1
> >> >
> >> > Dim cmdConn As SqlClient.SqlCommand
> >> >
> >> > Dim cmdSource As SqlClient.SqlDataReader
> >> >
> >> > Dim other stuff
> >> >
> >> > try
> >> >
> >> > Instantiate the objects and do the business
> >> >
> >> > Catch
> >> >
> >> > logging error etc
> >> >
> >> > Finally
> >> >
> >> > cmdSource.Close()
> >> >
> >> > cmdConn.Dispose()
> >> >
> >> > End Try
> >> >
> >> > Now in CLR 2.0 I am warned that the finally block is using unassigned
> >> > variables. (Which it is)
> >> >
> >> > I am tempted to ditch the finally clause and leave it to the Garbage
> >> > collector.
> >> >
> >> > What is the recommended code structure in this situation.
> >> >
> >> > Thanks
> >> >
> >> > Bob
> >> >
> >> >
> >>
> >>
> >
> >
>
>