Home All Groups Group Topic Archive Search About

Context Connection & Using

Author
24 Nov 2007 8:35 PM
Scott M.
When working with the SQL CLR, should I be using "using" when referring to
the "context connection"?

Author
26 Nov 2007 4:13 AM
WenYuan Wang [MSFT]
Hello Scott,

According to your description, you want to know if we should wrap the
connection with "using" blocks in SQL CLR, correct? If I misunderstood
anything here, please don't hesitate to correct me.

In my opinion, working with the Using Block is recommended, but no
necessary.
Working with using block guarantees disposal of the resources, no matter
how we exit the block. However, if you make sure you will close the
connection by yourself, it is not necessary to put it into Using Block
again.

Hope this helps. Please feel free to update there again, if there is
anything unclear. We are glad to assist you.

Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Author
26 Nov 2007 5:48 PM
Scott M.
Hi Wen,

Thanks for you response.

I am aware of what using does and agree that if you manage the connection
correctly, its use is not needed.  My question is a bit more involved than
this though.  When using the context connection in SQL CLR, should Using be
used (or if I am managing the connection myself, should I be closing and
disposing it)?

The point being that the context connection represents the connection that
that calling code is using.  If I were to close and dispose of that
connection in the SQL CLR code, then wouldn't that have ramifications on the
caller's ability to continue to use the connection if desired?

-Scott

Show quote
"WenYuan Wang [MSFT]" <v-wyw***@online.microsoft.com> wrote in message
news:%23tGuwK%23LIHA.7908@TK2MSFTNGHUB02.phx.gbl...
> Hello Scott,
>
> According to your description, you want to know if we should wrap the
> connection with "using" blocks in SQL CLR, correct? If I misunderstood
> anything here, please don't hesitate to correct me.
>
> In my opinion, working with the Using Block is recommended, but no
> necessary.
> Working with using block guarantees disposal of the resources, no matter
> how we exit the block. However, if you make sure you will close the
> connection by yourself, it is not necessary to put it into Using Block
> again.
>
> Hope this helps. Please feel free to update there again, if there is
> anything unclear. We are glad to assist you.
>
> Have a great day,
> Best regards,
>
> Wen Yuan
> Microsoft Online Community Support
> ==================================================
> Get notification to my posts through email? Please refer to
> http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
> ications.
>
> Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
> where an initial response from the community or a Microsoft Support
> Engineer within 1 business day is acceptable. Please note that each follow
> up response may take approximately 2 business days as the support
> professional working with you may need further investigation to reach the
> most efficient resolution. The offering is not appropriate for situations
> that require urgent, real-time or phone-based interactions or complex
> project analysis and dump analysis issues. Issues of this nature are best
> handled working with a dedicated Microsoft Support Engineer by contacting
> Microsoft Customer Support Services (CSS) at
> http://msdn.microsoft.com/subscriptions/support/default.aspx.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
Author
27 Nov 2007 9:14 AM
WenYuan Wang [MSFT]
Hello Scott,

It sound like your main concern is if closing/disposing the connection in
SQLCLR code will effect on the caller's ability to continue to use the
connection, correct? Please don't hesitate to correct me, if I
misunderstood anything again.

SQL CLR creates new connection with the same context of caller's connection
in his code. It doesn't use caller's connection. They are not the same
connection. Thereby, (as far as I know), whatever we do on the context
connection, this will not effect on the caller's connection.

Hope this helps. Please feel free to update here again, if there is
anything unclear. We are glad to assist you.
Have a great day,
Best regards,

Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

AddThis Social Bookmark Button